Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1795150pxb; Sat, 29 Jan 2022 17:56:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8uTM8mTm/RWYJ2TeonUmUdhcgm1cFsWvAGJLO7jc26ZCAm0DooyliMSTTxFpTGKijAJjC X-Received: by 2002:a17:906:c5b:: with SMTP id t27mr12249942ejf.317.1643507813924; Sat, 29 Jan 2022 17:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643507813; cv=none; d=google.com; s=arc-20160816; b=s9QffSZPSDISkNnZWzSPyw+IbCNBOA9jaddyXxKL6UT7nQViCK0GNXoyK8b1VuVcHL yDluj/c97kQ0nqUuLDroYQpCBCsxZOfuh0om9mwpGsOo85b9Nkef4+6ZoqsZ/B+KhqtP EMcIiKFAGdl7S910ROQBP13NWaqevK7qrk61Ppm19yrTwTUsiegFaVo+DuWd7KumPUAx O/B8PtIVEcJCtpVQOacAxxXpIlMWnPGGagZQ7iFr8+sYbVCoxclImZ74JRle3+Igsiu+ jNq9qABLFObFs0qhfmRLcWVkq4pQAtZiW3Ii/HsywevIeSegTqMF9ceJdaR+Hricw+2F 6Y+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=9Xk+4cliWQ8pKs4/H9QbNIvJzjxoe0JvtSnu86eAs+0=; b=Gejuy2FzqtidveLUk2vnd1j2PmmCC/zJeT901voVII6xuqbkjAYBzXo9WL22ekBIcS wNGgPsBgBftcduQqatSoJgYAubCbCyNhq3O/tiirdePotfwlSeariJLoh/ZoFqg7IYvi 94v/WY1WGnjhcmQqBrte+NIIv0JJcMUysEGtRX1+LQD2fI5XlRGuJ3mCRh9qPmQU62dZ u9KP9E+7ExLg6Cc/s64RvMBbtNO/04hHM8o7sob2ezifp1iFRYwmMf/Azelpbq1U2hPg /dAdq/R4Mgi1KAd2lWr9i/O0PcgCv00YWF8AdLRQxKcS7/J4CuNY6a25DX7lveL2BdAf PxMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sIvai0pL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g10si5268033edq.27.2022.01.29.17.56.17; Sat, 29 Jan 2022 17:56:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sIvai0pL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346564AbiA1GpE (ORCPT + 99 others); Fri, 28 Jan 2022 01:45:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233328AbiA1GpD (ORCPT ); Fri, 28 Jan 2022 01:45:03 -0500 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C6FBC061714 for ; Thu, 27 Jan 2022 22:45:03 -0800 (PST) Received: by mail-ot1-x334.google.com with SMTP id g15-20020a9d6b0f000000b005a062b0dc12so4873264otp.4 for ; Thu, 27 Jan 2022 22:45:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9Xk+4cliWQ8pKs4/H9QbNIvJzjxoe0JvtSnu86eAs+0=; b=sIvai0pLLwJ9w4NB1MoADJyrAGiPV0/20B6pBBp7Ff+aX15M7nHLfTxFwVhjhtonYU TbNxZSQ8CZJ1+YdNgCmymBIKbdZcJsXjpnLPRJ/pIzo0BsnIw4C0L8SGuJufIL3ln6xv IkXdIfatAe6ivIBV2fmOvyXTz7BRUSHKSbiHx4Pu4y2kH3DU32t2jIhJjgAvxdpvMt7s 7gPJnjKmZA9hTSIWopMqc84wJzJEnMbTjqVrgCjfNULZ5qws0UHG9gfueX/MSbbqUjkB N39srS8ePQl44gORjhNbPhj6Twgwb46yJj1UwrFJkT2in4B8xN/YsGmfau3La1aL7dCH Vx3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=9Xk+4cliWQ8pKs4/H9QbNIvJzjxoe0JvtSnu86eAs+0=; b=XX2y32Zgipb/KRyU4yk/DEZnITDmr0PoscWYTJlQwtCc5mkyhHvdcaIhLWIw26QiqF 9L9xeHhkMgQ8J5M/Y2mhguRVFRZO3OVfjpXeH46ePDy6OCDcYh+132HG7GE3ZrBLYaPL ASnB6bpZ5Wf9UczaeyhSE7/OJYloNcZlrLJezlU8lIBToET7lPT3N44LH+7bGt00BWzN Xr8/C9+rXnHctJpwueHkiYMZOtJQmxVXBZnnp3rmcan9ZRR2Df7jB4yuTw4d2b5VD6Qz /pKs6NbCz5uiu1XXaHezPCADbTZem5qMNlx0vQVvzV0ANeYhWavlDjwQpw37irFl/h6N S88g== X-Gm-Message-State: AOAM530AKsJMArMYVpfz7STkjHmWIv8e9umvkyg3ILlf01/sweQbWe0A KKjWCjzSrNL6BETnDHrnduwgdNXPCwMc1EwUwdILkQ== X-Received: by 2002:a9d:6319:: with SMTP id q25mr3982948otk.137.1643352302180; Thu, 27 Jan 2022 22:45:02 -0800 (PST) MIME-Version: 1.0 References: <20220128000752.2322591-1-jannh@google.com> In-Reply-To: <20220128000752.2322591-1-jannh@google.com> From: Dmitry Vyukov Date: Fri, 28 Jan 2022 07:44:50 +0100 Message-ID: Subject: Re: [PATCH v2] x86/csum: Add KASAN/KCSAN instrumentation To: Jann Horn Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , kasan-dev@googlegroups.com, Eric Dumazet Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 28 Jan 2022 at 01:08, Jann Horn wrote: > > In the optimized X86 version of the copy-with-checksum helpers, use > instrument_*() before accessing buffers from assembly code so that KASAN > and KCSAN don't have blind spots there. > > Signed-off-by: Jann Horn Reviewed-by: Dmitry Vyukov Thanks > --- > > Notes: > v2: use instrument_copy_{from,to}_user instead of instrument_{read,write} > where appropriate (dvyukov) > > arch/x86/lib/csum-partial_64.c | 3 +++ > arch/x86/lib/csum-wrappers_64.c | 9 +++++++++ > 2 files changed, 12 insertions(+) > > diff --git a/arch/x86/lib/csum-partial_64.c b/arch/x86/lib/csum-partial_64.c > index 1f8a8f895173..8b0c353cd212 100644 > --- a/arch/x86/lib/csum-partial_64.c > +++ b/arch/x86/lib/csum-partial_64.c > @@ -8,6 +8,7 @@ > > #include > #include > +#include > #include > #include > > @@ -37,6 +38,8 @@ __wsum csum_partial(const void *buff, int len, __wsum sum) > u64 temp64 = (__force u64)sum; > unsigned odd, result; > > + instrument_read(buff, len); > + > odd = 1 & (unsigned long) buff; > if (unlikely(odd)) { > if (unlikely(len == 0)) > diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c > index 189344924a2b..c44973b8f255 100644 > --- a/arch/x86/lib/csum-wrappers_64.c > +++ b/arch/x86/lib/csum-wrappers_64.c > @@ -6,6 +6,8 @@ > */ > #include > #include > +#include > +#include > #include > #include > > @@ -26,6 +28,7 @@ csum_and_copy_from_user(const void __user *src, void *dst, int len) > __wsum sum; > > might_sleep(); > + instrument_copy_from_user(dst, src, len); > if (!user_access_begin(src, len)) > return 0; > sum = csum_partial_copy_generic((__force const void *)src, dst, len); > @@ -51,6 +54,7 @@ csum_and_copy_to_user(const void *src, void __user *dst, int len) > __wsum sum; > > might_sleep(); > + instrument_copy_to_user(dst, src, len); > if (!user_access_begin(dst, len)) > return 0; > sum = csum_partial_copy_generic(src, (void __force *)dst, len); > @@ -71,6 +75,8 @@ EXPORT_SYMBOL(csum_and_copy_to_user); > __wsum > csum_partial_copy_nocheck(const void *src, void *dst, int len) > { > + instrument_write(dst, len); > + instrument_read(src, len); > return csum_partial_copy_generic(src, dst, len); > } > EXPORT_SYMBOL(csum_partial_copy_nocheck); > @@ -81,6 +87,9 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr, > { > __u64 rest, sum64; > > + instrument_read(saddr, sizeof(*saddr)); > + instrument_read(daddr, sizeof(*daddr)); > + > rest = (__force __u64)htonl(len) + (__force __u64)htons(proto) + > (__force __u64)sum; > > > base-commit: 0280e3c58f92b2fe0e8fbbdf8d386449168de4a8 > -- > 2.35.0.rc0.227.g00780c9af4-goog >