From patchwork Tue Aug 4 12:41:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 254292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18455C433E1 for ; Tue, 4 Aug 2020 12:42:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EED952067D for ; Tue, 4 Aug 2020 12:42:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="El9eCMgZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbgHDMmc (ORCPT ); Tue, 4 Aug 2020 08:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbgHDMlj (ORCPT ); Tue, 4 Aug 2020 08:41:39 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0AD5C06179E for ; Tue, 4 Aug 2020 05:41:38 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id z10so5136754qvm.0 for ; Tue, 04 Aug 2020 05:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=MkWKUi7xJlcxy+e8OWBoJNl1OXW3h1d9K35k1It603c=; b=El9eCMgZto7hrv7PDOK8sz2wSLBcDVP89TfYWUHfgVCBju0bnGiOsMLl6XBn8jPSjh qrgdXGRXN4HlmL1fOGf8voLbPZt1X18PEjYdDjjXTh3PKpwhCwvxfdH77PmSuIH6bHjH IzHWS/61LABdVG/cl9nv7tSaT02sva1I2t9kU4CCxKn2Fuq5zAhsavQCtRi26JwEs+Dl 9fQdx9ceg+7jPTrfJr2H/RPbendmsnMPAjmTuZXHQ5z0+weqjI1akX4ATVsuIjOK4K4K 9i8R5X/OYsJ9UZwUQgh+6iCBRktsvnPbggGzIRvclgIctl5ElMdM+aNZB9sDbsroXJJs M9ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MkWKUi7xJlcxy+e8OWBoJNl1OXW3h1d9K35k1It603c=; b=Lnmew3suIoZSKd9wfoxaU0xR19QWl7VlB+09gT/fDJK+Lfvz/LR1JpOngrZn+O1KFb b69ttL86x0QUbinT1vfnlSbF0LXiBXGFDp1GLy5Q2Dyulejka9857sD9cP8Cu8pMI/5y qVnMohrVmIwmGlXg3cKUBWtToYHrLGOfxVjid7Al+/++vHphtvOV/vKFr8jbsd1FyNSd lCP7/Q1F2mxiCAxMHAIy4t54yvCdYv97Ii7551vwzkRSAT7f6rudaHq19LlKf4WV7IS2 VlGWHmkeB04Tmy0i9v49ZzRNSQO5hu4NG1e5ZMEaJxAUhSY046NyAyWN7B6E/CVnE9HT JDKQ== X-Gm-Message-State: AOAM5310tNXLq8d9IJRPhkNa0J6JdA48hk3MAUE4E+qiFduMoCkKopJN sZlXsFeZBqCACxSwcMb4Bc40kObDSLWQgB4L X-Google-Smtp-Source: ABdhPJwC+zlXBovbZ5yMemFd6n1F3dx7E2v/1/0xLypGVzYOL4r1AHzTFwqN6hvHO5BmR1xUzcpuB+Tj4Xl/elq0 X-Received: by 2002:ad4:4152:: with SMTP id z18mr22181844qvp.42.1596544898043; Tue, 04 Aug 2020 05:41:38 -0700 (PDT) Date: Tue, 4 Aug 2020 14:41:25 +0200 In-Reply-To: Message-Id: <6514652d3a32d3ed33d6eb5c91d0af63bf0d1a0c.1596544734.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog Subject: [PATCH v2 2/5] efi: provide empty efi_enter_virtual_mode implementation From: Andrey Konovalov To: Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Marco Elver , Ard Biesheuvel , Arvind Sankar , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Walter Wu , Elena Petrova , Vincenzo Frascino , Catalin Marinas , Andrey Konovalov , kernel test robot Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org When CONFIG_EFI is not enabled, we might get an undefined reference to efi_enter_virtual_mode() error, if this efi_enabled() call isn't inlined into start_kernel(). This happens in particular, if start_kernel() is annodated with __no_sanitize_address. Reported-by: kernel test robot Signed-off-by: Andrey Konovalov --- include/linux/efi.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index 05c47f857383..73db1ae04cef 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -606,7 +606,11 @@ extern void *efi_get_pal_addr (void); extern void efi_map_pal_code (void); extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg); extern void efi_gettimeofday (struct timespec64 *ts); +#ifdef CONFIG_EFI extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */ +#else +static inline void efi_enter_virtual_mode (void) {} +#endif #ifdef CONFIG_X86 extern efi_status_t efi_query_variable_store(u32 attributes, unsigned long size, From patchwork Tue Aug 4 12:41:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 254293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5747C433DF for ; Tue, 4 Aug 2020 12:42:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A517C208A9 for ; Tue, 4 Aug 2020 12:42:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="epaWaJlt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726282AbgHDMmc (ORCPT ); Tue, 4 Aug 2020 08:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbgHDMlr (ORCPT ); Tue, 4 Aug 2020 08:41:47 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64DD1C0617A0 for ; Tue, 4 Aug 2020 05:41:42 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id t12so12675297wrp.0 for ; Tue, 04 Aug 2020 05:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KTaExCeIbMBtrg6f3KaFtKJ9kXln1IxZOo4x1K8ywoo=; b=epaWaJlt64ntx42FNABLMyLva14SlmdYcoGzzYGyrXWUnAJnxMu5GEZgilr7YOjQyg rwN+m322Ym4K72DntPYQLTQpUlUsvtp9hOED35dktAjWzCeoMAdqgWFu+8q67qvVGdd0 ASSvypkGepo2fVM74GawP/zGW8ARgykh7GWGHusAgWS8l/UBxb0pdkO0TYQ7EmgRfqVS +AhohRsPKYfLCyuszVYf5jaiW3P7HKDO0xMW0AxuHSElSjjWJ6UveE2t2MgCnIL+ItDv /1ed6bLGDRty9mFhZhCq6dEUtquKavGW9+Vz9/sId52Rf88V2RXw/k9gqiVHbxbaBWtN +9hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KTaExCeIbMBtrg6f3KaFtKJ9kXln1IxZOo4x1K8ywoo=; b=Ab8VLR06G6B05Vs+YOpJHU2FSOUU3EyYk1FDCpw44nR9QRzOC/aOgbyVQy74Q/to9b 0ZBXe5B/HnTdDUkjzUf5qPrGwPoa0hvs6v4A145dgZI43YuCcOu8OKbtWhgQYo+HLTql geIKnKNfW5wq9AFzytarGOuzbeoJljrZITi+OGtx7uFKGL5hFtRJyy8k4RT6ioZ33bss IgurJcDc/KCc8s5XslccJGdLodzzrNPTnVhfjvyfS0b3V4RsMUmSCFTjE/ZedB57o1O5 Yuta+4AxO0gD4WEy0ufpDIW+xCr6uBxn3vPa47o1tbOI+tv71O158xu5gRMz2Mp5REYn 0cng== X-Gm-Message-State: AOAM530SpJHylOYHuZ3naSvmThoGiSoFgK4mumdLzGYH7wjd1mmMARxd BFbL+3WMDhKw80494fq1Mzt9tvDyDMwrYTPr X-Google-Smtp-Source: ABdhPJwWjosW9Y2ZD4qtR2i07CuuW2KOWsc+Y1P+/2KrTNBkB6pCcdGVRsu0tHMa3wVdBR/M1mpyQCpyke7nl0k9 X-Received: by 2002:a7b:cd93:: with SMTP id y19mr492659wmj.0.1596544900281; Tue, 04 Aug 2020 05:41:40 -0700 (PDT) Date: Tue, 4 Aug 2020 14:41:26 +0200 In-Reply-To: Message-Id: <26fb6165a17abcf61222eda5184c030fb6b133d1.1596544734.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog Subject: [PATCH v2 3/5] kasan, arm64: don't instrument functions that enable kasan From: Andrey Konovalov To: Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Marco Elver , Ard Biesheuvel , Arvind Sankar , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Walter Wu , Elena Petrova , Vincenzo Frascino , Catalin Marinas , Andrey Konovalov Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org This patch prepares Software Tag-Based KASAN for stack tagging support. With stack tagging enabled, KASAN tags stack variable in each function in its prologue. In start_kernel() stack variables get tagged before KASAN is enabled via setup_arch()->kasan_init(). As the result the tags for start_kernel()'s stack variables end up in the temporary shadow memory. Later when KASAN gets enabled, switched to normal shadow, and starts checking tags, this leads to false-positive reports, as proper tags are missing in normal shadow. Disable KASAN instrumentation for start_kernel(). Also disable it for arm64's setup_arch() as a precaution (it doesn't have any stack variables right now). Signed-off-by: Andrey Konovalov --- arch/arm64/kernel/setup.c | 2 +- init/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 93b3844cf442..575da075a2b9 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -276,7 +276,7 @@ arch_initcall(reserve_memblock_reserved_regions); u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; -void __init setup_arch(char **cmdline_p) +void __init __no_sanitize_address setup_arch(char **cmdline_p) { init_mm.start_code = (unsigned long) _text; init_mm.end_code = (unsigned long) _etext; diff --git a/init/main.c b/init/main.c index 0ead83e86b5a..7e5e25d9fe42 100644 --- a/init/main.c +++ b/init/main.c @@ -827,7 +827,7 @@ void __init __weak arch_call_rest_init(void) rest_init(); } -asmlinkage __visible void __init start_kernel(void) +asmlinkage __visible void __init __no_sanitize_address start_kernel(void) { char *command_line; char *after_dashes; From patchwork Tue Aug 4 12:41:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 254294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BECE7C433DF for ; Tue, 4 Aug 2020 12:42:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CA48208C7 for ; Tue, 4 Aug 2020 12:42:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ea5YjJ7o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727116AbgHDMmA (ORCPT ); Tue, 4 Aug 2020 08:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727819AbgHDMlr (ORCPT ); Tue, 4 Aug 2020 08:41:47 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF141C0617A4 for ; Tue, 4 Aug 2020 05:41:45 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id k35so23773369qtk.9 for ; Tue, 04 Aug 2020 05:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OJV+wFsSuBAEdua9Kpud4j6ZGzVdRXqmU9/PZhjVLdc=; b=Ea5YjJ7o620kZq8eHnshiekvC4wpoxtU/m2L83KMHr56wGFqcLIiluwTTPIuK6jPtz NIbahZxx/kLpiZOWX4LifN1sYL8ve+GY+nJ4uXKX/NwgeJ66FB0oBHFDCJ7CnFI+jXp5 YfjHAXZMMGH3A1RBkM5ekVG/ygZ56FsWNDeUBLLVL1ABwVsRZPV6DZg8v5EyPdnyI/8q u9+woephvoS6hP7AP7QtlnSDcnrQ3oLlLY/jprakwQVQNuaNzYsx0faunrqjJ1Rwi828 vpjJ63tAJJETQeQAfpWW300WdlbW294wpGLA7b0wjZ0R/4TF1hESmC/l3kgC9ReY8bHQ oJZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OJV+wFsSuBAEdua9Kpud4j6ZGzVdRXqmU9/PZhjVLdc=; b=L0txTXhJC4nnxCQhGFEjC/StDXZl6Iz4nhAIvzzHQ+4nsO6eC8LI+tKQbjsP/Mwg7d aV0GSfxvZplL6AZunR6o2A4EOp78cKb4nA/1a3JPGqv2QZyKGIxJZjzQZPe7aX/l9zbv ygiQBc8U6nRodcHH4QNs5LE15UaCVAnGYnwdPfWrI1y87c+winM7vTLKB8l7B8j0emSE FyALEGXL8u6yv/ibHTYaaiU0UpphIoIjrvYKtrqSL95S7bqbYTHjs6GEtR5+skFm4Wjc VyAnlkmwIj3KQ+6xslfWJLyrWMtP6pxqPtEARU5o31N6BKq8Dhu4DSLaD/DT083HLDG3 FXrQ== X-Gm-Message-State: AOAM5304MSXpVpShUReB3/SGPvj116M+DHaFt6d6hlO8A7GAz48ewC7F y0gH+OZfIEBF8SE3cc/wyQtpikeuAjwXL085 X-Google-Smtp-Source: ABdhPJxMCD1uy5OtH/rfQcGvmBrhxSjZNftrKmDoPQf463mdE8fRrlNv8GbsPVw+FCZ38SV1RL/Err4XbOOp0GEM X-Received: by 2002:a0c:b604:: with SMTP id f4mr15297001qve.68.1596544904936; Tue, 04 Aug 2020 05:41:44 -0700 (PDT) Date: Tue, 4 Aug 2020 14:41:28 +0200 In-Reply-To: Message-Id: <3063ab1411e92bce36061a96e25b651212e70ba6.1596544734.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.163.g6104cc2f0b6-goog Subject: [PATCH v2 5/5] kasan: adjust kasan_stack_oob for tag-based mode From: Andrey Konovalov To: Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Marco Elver , Ard Biesheuvel , Arvind Sankar , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, Walter Wu , Elena Petrova , Vincenzo Frascino , Catalin Marinas , Andrey Konovalov Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Use OOB_TAG_OFF as access offset to land the access into the next granule. Suggested-by: Walter Wu Signed-off-by: Andrey Konovalov --- lib/test_kasan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 7674616d0c37..5d3f496893ef 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -488,7 +488,7 @@ static noinline void __init kasan_global_oob(void) static noinline void __init kasan_stack_oob(void) { char stack_array[10]; - volatile int i = 0; + volatile int i = OOB_TAG_OFF; char *p = &stack_array[ARRAY_SIZE(stack_array) + i]; pr_info("out-of-bounds on stack\n");