Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1166244lqo; Fri, 17 May 2024 12:50:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnBTDAFIJqw38deGmQa4ao1IrGC3m9uuvEn5nvomqh5F96yg7IuYHs4FvTyGtA1hfXc5k3zyYJ73fNrdlgFDK6uOdphst2G+ntyPXwJA== X-Google-Smtp-Source: AGHT+IFTmpEKknu01XwL0n38X7HqAMlJJaRpMqQPzPviBRcDa56fZlhWW7LBDc8tu56G+7dpqf3T X-Received: by 2002:a05:6808:2cb:b0:3c9:6a21:8cb4 with SMTP id 5614622812f47-3c9970581fbmr23292109b6e.18.1715975451172; Fri, 17 May 2024 12:50:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715975451; cv=pass; d=google.com; s=arc-20160816; b=JBpYuBhKQ8h0I3eu6n1ZmoAKEZ4okUEnCjtW8JtdZ2CvmTX2W2czjSytvI9l5ajZGc 3vtz9WuMmqKTnZwwVckx88s6YFoyZYU3OLJTVmbQyh9s63QesEU5SoEu/dSWzSZabBVq rJWVYi2mkaU7o4E40Alooj6s3+Zv9NZ1cxB2r7fhOmwb96f/tMNNRYgb5xGR4xrToEg6 oyi1M4wHNuKwpLK0mSzZ5BCwpfSIIowKEmIbOnAQxwNWOTVFR66u6ppsmG868rT5PNQW MWU7IMneGUu6MhGMV8z3BfQlX5KWOTnwZPuyJF67dncs9szUh0oYlSmbFSPVgi7b3JOv 8OYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=1bxakr/BFBoeB5Z7JNvpJE420hX0IdbRkXcnTw/5V8o=; fh=eisKQ3EaEM07GdrRt+tFd6B+Qr9ddkaDl+af0MvO/QU=; b=rX+fbn91Rxck2+//BhOMJkYwVIqPoSF0/+cSe1VWNgsli4iXQfPf0ImM+QSF++hTLF a/jB32m2kvPs8nQtrxl17TQnwEyEeIbcdLh/s73G9UAQddrIadcYSyXyr4J4U3SvL+G8 Bh5pUnBdF0jjxjLbWtUVKnCZXaPDqxIn85oJq669oLkjty6FT+jkXNMiFjBHBe41cL/z VBrHtnNDVYjHXoW3SZiPzn8Bxi/m2Tq58oz4s4glP5jHfKEjya+XZ4TPDo3MwStQZY7C LRjYWhxOEmCHucQZ8cZtmmLYfusrmuYQhIYPTkO4JTHnFbVhf3+z7Ip+LyeCf2fAsE4D xupQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gr9jCqjK; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-182583-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf2772f3si1912576185a.116.2024.05.17.12.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 12:50:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182583-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Gr9jCqjK; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-182583-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 89EBC1C22008 for ; Fri, 17 May 2024 19:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2F5E814037E; Fri, 17 May 2024 19:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gr9jCqjK" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51EE645007 for ; Fri, 17 May 2024 19:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715975442; cv=none; b=ekt45jPfJh8wQb6/ErzkWuQYCKi9VpKrNVZHsJD7umBVMBAUhmLFCCmYHOeEnYEljLenaRFXaJwKbCHGLOEFBM9/rnHNcirqvdC8cFyHQCQU+G8x8njxSkfyRyW7xp9zGRx3QboGKQTlct0Ut7MgzdXV9JVHfRq0DxNbMDzPYSc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715975442; c=relaxed/simple; bh=XvCCKx8tFEqP1/BD+I3XNnGYNbZ5f6J3SCFAICBZd0w=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=kNotMG3VL99jlgirGIHQBsAW1mUHk8khvNht1uofiszM1tSEEyd6Brgd1ySl8QtFkUpdtc4M4VBQhi1D9HmDHVrKFmb8ANSpaT3YgQ/i+FF+QHw0LbECjnuvunyRMZDKHnFbDVtQiw5b80oIeGFYjMdZvzdTFTLbTat5uFAxsBo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Gr9jCqjK; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715975439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1bxakr/BFBoeB5Z7JNvpJE420hX0IdbRkXcnTw/5V8o=; b=Gr9jCqjKifWM9mMN5HXKXVoXQhvJ144mbxGEjIK2YFLhK9rey1zwcuIbrEb83A8jdsOMhW 3FlyYgnigTJtNglHkEKee7LI1UB2XHTAda7516xAw+hF1PB6P/hqhYQKIYi15/xGXI8SI/ vuRifMwLFvhatGCUSWzsx2MN2QQZi0U= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-y-wtZTZDPSqU9-D7nbH0_A-1; Fri, 17 May 2024 15:50:37 -0400 X-MC-Unique: y-wtZTZDPSqU9-D7nbH0_A-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-61be452c62bso143785727b3.2 for ; Fri, 17 May 2024 12:50:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715975437; x=1716580237; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1bxakr/BFBoeB5Z7JNvpJE420hX0IdbRkXcnTw/5V8o=; b=GtD1RDVoaXJHim2AtuGfKZzMm52fnho+cqTo9FseWATxVsKdyWIbOIIJiY+1n4pqqu YrI34n4ZJeaOeOHXaXVw1ah55WdWsG/YMwQMBBGk4OQgx+sp7GAqu7+2OTtQ/BDdzMP+ c8l7jyaGSYXMWPU+lxNEO1gAJh3V4yNjhlp8nN1LtPg/DaKzFmPJczyyOFE7iJ5DAYUJ KvjN6ss12hAogOK/TjWNssGc0Ghmuf9eOIHFKzbr64ce1QK0EI0USou4YeRPKMsfXnCo cCfdI2ZDfOZBCT60bb7pHtzC/d3tcVPAXtY3bqgz0+8kopg4/3JjKS7PPxBXtlcW9IFF l1Kw== X-Forwarded-Encrypted: i=1; AJvYcCXgdfOecO8a4ykX7eB+5AOGKZvftsO+mIpo56tvXVSw4MHS2F7MQ/+l9Bc2fEreNC9G39Z5fntW0DO5CUkzRwXeAyYEkNu7+ssg5gZq X-Gm-Message-State: AOJu0YxtC9nBv0tPe0VDAI8OCUK0dpkr86mqGd5aVbLAydaKYebHpsZa N90JU9MMvA0VPFxXQOe95uul/Poq8QrAD97CpMVFtUf9omG0BzC8puXsUYA0+D2xWttldXCdQT5 n6UlFkwWhsfjgnNJXeEWKGBwyiuhYNWjl5BgDKtpzlEBESkTg0n8VdWmKBpA9fhF/bmNDNcL9et ald8d/WQFWJi9cgre9Nn5SAsbwiFA/dbJOYYNK X-Received: by 2002:a05:690c:6401:b0:615:35e1:e512 with SMTP id 00721157ae682-622afdb76b9mr250824487b3.0.1715975437070; Fri, 17 May 2024 12:50:37 -0700 (PDT) X-Received: by 2002:a05:690c:6401:b0:615:35e1:e512 with SMTP id 00721157ae682-622afdb76b9mr250824237b3.0.1715975436677; Fri, 17 May 2024 12:50:36 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240517130118.759301-1-andrey.konovalov@linux.dev> In-Reply-To: <20240517130118.759301-1-andrey.konovalov@linux.dev> From: Nico Pache Date: Fri, 17 May 2024 13:50:10 -0600 Message-ID: Subject: Re: [PATCH] kasan, fortify: properly rename memintrinsics To: andrey.konovalov@linux.dev Cc: Marco Elver , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Andrew Morton , linux-mm@kvack.org, Erhard Furtner , Daniel Axtens , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 17, 2024 at 7:02=E2=80=AFAM wrote: > > From: Andrey Konovalov > > After commit 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() > functions") and the follow-up fixes, with CONFIG_FORTIFY_SOURCE enabled, > even though the compiler instruments meminstrinsics by generating calls > to __asan/__hwasan_ prefixed functions, FORTIFY_SOURCE still uses > uninstrumented memset/memmove/memcpy as the underlying functions. > > As a result, KASAN cannot detect bad accesses in memset/memmove/memcpy. > This also makes KASAN tests corrupt kernel memory and cause crashes. > > To fix this, use __asan_/__hwasan_memset/memmove/memcpy as the underlying > functions whenever appropriate. Do this only for the instrumented code > (as indicated by __SANITIZE_ADDRESS__). > > Reported-by: Erhard Furtner > Reported-by: Nico Pache > Closes: https://lore.kernel.org/all/20240501144156.17e65021@outsider.home= / > Fixes: 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() funct= ions") > Fixes: 51287dcb00cc ("kasan: emit different calls for instrumentable memi= ntrinsics") > Fixes: 36be5cba99f6 ("kasan: treat meminstrinsic as builtins in uninstrum= ented files") > Signed-off-by: Andrey Konovalov Thank you for fixing this !! The test no longer panics :) Now that the test progresses I also see rcu_uaf failing. # rcu_uaf: EXPECTATION FAILED at mm/kasan/kasan_test.c:870 KASAN failure expected in "call_rcu(&global_rcu_ptr->rcu, rcu_uaf_reclaim); rcu_barrier()", but none occurred not ok 31 rcu_uaf I can open a new thread for that if you'd like. Tested-by: Nico Pache Acked-by: Nico Pache > --- > include/linux/fortify-string.h | 22 ++++++++++++++++++---- > 1 file changed, 18 insertions(+), 4 deletions(-) > > diff --git a/include/linux/fortify-string.h b/include/linux/fortify-strin= g.h > index 85fc0e6f0f7f..bac010cfc42f 100644 > --- a/include/linux/fortify-string.h > +++ b/include/linux/fortify-string.h > @@ -75,17 +75,30 @@ void __write_overflow_field(size_t avail, size_t want= ed) __compiletime_warning(" > __ret; \ > }) > > -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) > +#if defined(__SANITIZE_ADDRESS__) > + > +#if !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX) && !defined(CONFIG= _GENERIC_ENTRY) > +extern void *__underlying_memset(void *p, int c, __kernel_size_t size) _= _RENAME(memset); > +extern void *__underlying_memmove(void *p, const void *q, __kernel_size_= t size) __RENAME(memmove); > +extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t= size) __RENAME(memcpy); > +#elif defined(CONFIG_KASAN_GENERIC) > +extern void *__underlying_memset(void *p, int c, __kernel_size_t size) _= _RENAME(__asan_memset); > +extern void *__underlying_memmove(void *p, const void *q, __kernel_size_= t size) __RENAME(__asan_memmove); > +extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t= size) __RENAME(__asan_memcpy); > +#else /* CONFIG_KASAN_SW_TAGS */ > +extern void *__underlying_memset(void *p, int c, __kernel_size_t size) _= _RENAME(__hwasan_memset); > +extern void *__underlying_memmove(void *p, const void *q, __kernel_size_= t size) __RENAME(__hwasan_memmove); > +extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t= size) __RENAME(__hwasan_memcpy); > +#endif > + > extern void *__underlying_memchr(const void *p, int c, __kernel_size_t s= ize) __RENAME(memchr); > extern int __underlying_memcmp(const void *p, const void *q, __kernel_si= ze_t size) __RENAME(memcmp); > -extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t= size) __RENAME(memcpy); > -extern void *__underlying_memmove(void *p, const void *q, __kernel_size_= t size) __RENAME(memmove); > -extern void *__underlying_memset(void *p, int c, __kernel_size_t size) _= _RENAME(memset); > extern char *__underlying_strcat(char *p, const char *q) __RENAME(strcat= ); > extern char *__underlying_strcpy(char *p, const char *q) __RENAME(strcpy= ); > extern __kernel_size_t __underlying_strlen(const char *p) __RENAME(strle= n); > extern char *__underlying_strncat(char *p, const char *q, __kernel_size_= t count) __RENAME(strncat); > extern char *__underlying_strncpy(char *p, const char *q, __kernel_size_= t size) __RENAME(strncpy); > + > #else > > #if defined(__SANITIZE_MEMORY__) > @@ -110,6 +123,7 @@ extern char *__underlying_strncpy(char *p, const char= *q, __kernel_size_t size) > #define __underlying_strlen __builtin_strlen > #define __underlying_strncat __builtin_strncat > #define __underlying_strncpy __builtin_strncpy > + > #endif > > /** > -- > 2.25.1 >