From patchwork Wed Nov 2 11:06:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 14178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3555644wru; Wed, 2 Nov 2022 04:15:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62Y5TCRr5ZNgaJow6TMyNMT5EW8NVzB0Ip4Z1P8b4q2kPkvplZokUEhG2YEF1wz0+b/45/ X-Received: by 2002:a05:6a00:190a:b0:56c:123e:3e61 with SMTP id y10-20020a056a00190a00b0056c123e3e61mr24564334pfi.47.1667387726028; Wed, 02 Nov 2022 04:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667387726; cv=none; d=google.com; s=arc-20160816; b=IPahxeZjfp0m7yQecNoYYVBtpCtIYuec4HELBUdCNPFfmRxINAkm+afFcfECimuVJx EPpLNnXJcF9JDVjl215I99iu/qtop0loN1g8AJXNxBHUCcsOxOJZL1Rg+q6TwrK9Q8Q/ GmXjo19zKwchueDsHsASP5ZV8ZbOPS5lxyd0gR462I9SKPXh7nNy/hIg1R0P6y4k6Unr gR0s5dcHmNqSexkXCEhKRQB5S1R1asomycUUchkhNFCMQMo98atpAsQs6HtzcOCiLGM7 AJtKyPx9IRc5RSCyKRkkuJCjghkHhoErk51eCpbeQPiPPsI3PLg+C9KO3N9FzIp1rIk4 //tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=GIr2ezHJZytLhlXMK2PvYo8WU5NrIng/zb7hVbc1Lzg=; b=lwWX5LEnvfKr2DwTS5vAVJMOFGaSxyiDlIcU0I/0TXcRcfJwVwF3p7O8gFjgBQ55n3 dTxGG04/dlJTHSh9QrWpePVmPuysu0Q+juMOSNiksZAewMlR8ke0hRX5uDluCDexM+4A ew9Ry8ULGWGdU5wADGUqYuzxrYbExVsTwFRa2imW6iHDpykRywQDPT2KjyYSzsp3lB5U PhSfiK48kWb1i4K56q7FK7SYeqDqYAL9Rzdh62LSc8Hb6ihLBZBNC8o7Z4uibuJETINc 95JrmEiDNabIfDScwQ95y/vZY4rvqrhB44bH61RN4i7AUClS5C6MKdog+Fl0oonT42lt jucw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TDR2Qbrp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a63db42000000b00458ae7b0a24si16134427pgi.208.2022.11.02.04.15.13; Wed, 02 Nov 2022 04:15:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TDR2Qbrp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230313AbiKBLGV (ORCPT + 99 others); Wed, 2 Nov 2022 07:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbiKBLGT (ORCPT ); Wed, 2 Nov 2022 07:06:19 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23B8024945 for ; Wed, 2 Nov 2022 04:06:19 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id e8-20020a5b0cc8000000b006bca0fa3ab6so15973019ybr.0 for ; Wed, 02 Nov 2022 04:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GIr2ezHJZytLhlXMK2PvYo8WU5NrIng/zb7hVbc1Lzg=; b=TDR2QbrpbPk39MbEBp7QE2/LtaTl168eHDcSKXsTbYFm0J2N6gc1e1BbPZoiCjB8hU 9BaU4/mFK6rylWjr8RlezKIdwfyx6JEn4Xt+BuDRJzDqLGWxoSxMOuJisNk//4LKYqeo WmCgmQMbYt7wUV/ki7tYTWroZrWVcyodZ+cDyMos90rvZPUsmiKOw50wZWI3K4Yz2ekN hRPo9sFMvHxlZqZXXNZ4ZZ+etmzaSVqT7KWQmtgp0Yv1Qupyjg8fsdntbz4+2XCc848s GerrC3sXiYTqxNqrYQXvh3xr+wMLrxLHYxahoFSishfnQJ7qiPsqJNWKC1iXHXj2CqAF HCaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GIr2ezHJZytLhlXMK2PvYo8WU5NrIng/zb7hVbc1Lzg=; b=lvsNQwGNPpk0vQx28FEdeJZ+WldRaVfaRIdEWMnGtpN0eSLtS+YxQHMFXAbiT7AHUx /iE6XyKMYiQIWNwfK2vAz9Nscp16oyBSjG55erXSsLgNy9MVIGJcidLTrcK4UgiAJk8z 1CBGnT6h5VpvukmZcx2vquUyKNpWg/BkYiSz3n78B4SeDyQzHIdXzEhlEctxW7+YkahF NhAroIBAnr+uRMxoXdjLRvv1epZMM4VYUxTtedjUaxn/KKwOYbirRNU1aSn+R/C5y+5J 0ICnChvtZUz7qAS+wtQnd5LJEXF80RwZUzyFZh4a+FT0IGuVo63RYewVpzJa+BCwDzI7 m1ZA== X-Gm-Message-State: ACrzQf3a2ySV7Wt1Fn9e2DgB2m9jggyzneeLXSGRqYurl+2OBJj8qOcy X1vGHMnCj1OYCY5nShBKfb1a6+SUGxA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:7f41:af20:8:a96d]) (user=glider job=sendgmr) by 2002:a81:a0d5:0:b0:370:1a06:1b4a with SMTP id x204-20020a81a0d5000000b003701a061b4amr178816ywg.206.1667387178012; Wed, 02 Nov 2022 04:06:18 -0700 (PDT) Date: Wed, 2 Nov 2022 12:06:08 +0100 In-Reply-To: <20221102110611.1085175-1-glider@google.com> Mime-Version: 1.0 References: <20221102110611.1085175-1-glider@google.com> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102110611.1085175-2-glider@google.com> Subject: [PATCH 2/5] x86/uaccess: instrument copy_from_user_nmi() From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Dave Hansen , Kees Cook , Peter Zijlstra , x86@kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748382752130768012?= X-GMAIL-MSGID: =?utf-8?q?1748382752130768012?= Make sure usercopy hooks from linux/instrumented.h are invoked for copy_from_user_nmi(). This fixes KMSAN false positives reported when dumping opcodes for a stack trace. Cc: Andrew Morton Cc: Dave Hansen Cc: Kees Cook Cc: Peter Zijlstra (Intel) Cc: x86@kernel.org Signed-off-by: Alexander Potapenko Acked-by: Peter Zijlstra (Intel) --- arch/x86/lib/usercopy.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c index f1bb186171562..24b48af274173 100644 --- a/arch/x86/lib/usercopy.c +++ b/arch/x86/lib/usercopy.c @@ -6,6 +6,7 @@ #include #include +#include #include @@ -44,7 +45,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n) * called from other contexts. */ pagefault_disable(); + instrument_copy_from_user_before(to, from, n); ret = raw_copy_from_user(to, from, n); + instrument_copy_from_user_after(to, from, n, ret); pagefault_enable(); return ret;