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: 13027972 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48CB8C43217 for ; Wed, 2 Nov 2022 11:06:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D79048E0005; Wed, 2 Nov 2022 07:06:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D29078E0001; Wed, 2 Nov 2022 07:06:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF16A8E0005; Wed, 2 Nov 2022 07:06:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B10FC8E0001 for ; Wed, 2 Nov 2022 07:06:20 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 77CC21611E7 for ; Wed, 2 Nov 2022 11:06:20 +0000 (UTC) X-FDA: 80088223320.16.4BCE0D2 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 3220418000C for ; Wed, 2 Nov 2022 11:06:18 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id y6-20020a25b9c6000000b006c1c6161716so16013732ybj.8 for ; Wed, 02 Nov 2022 04:06:18 -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=B4KbLTmeFUswfJgW2q9nc24Ht2drFIhSpwJ+mh+IwVMVA/2wsrBwzyf+fk8it8zFI2 cSA09uFXO7xqgsNGI9Pc2Qwr1+A2y7WjY6KBJ0Y2QMo6hPhD1kqQ7q7qHEsWFY65mTph UHdycmKsKVCNF6f24KoQhOTQQoy6Vnf32BVMaLxpVYp2v0zC1MEHzSKr7Lx6x75LE/f5 3PEHnTWMEkxlqWzmCJ5Buvp+p+EPBL/Gq+c3zwo5M0/umELIaza4Q9/77foZnR4UBkJX AsQ9Q49fM/fu3T6EPmfeDuDOoZT8gtN6lEVH3mddk9ff8swLlQe8xenx18NAJeRwPKkA XW5g== X-Gm-Message-State: ACrzQf3EvMHxrPhMD0K4BGdbqBerjDxM0PIy2sMGVfHnLpYHFbrJAgz2 GunS9X1QlWhJ+rIc/L6rNkoGYyloTn0= X-Google-Smtp-Source: AMsMyM46EzUNxA/tJ+HneP2x8faa5lSnGZX9YuhwEIjs8mzU+29Tq9Wklfbi16zLxPqq+zIolz1gsMz28xE= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667387179; a=rsa-sha256; cv=none; b=maGu5pTqN7wmToBSGkTepcJZMiOO5U/hyFTWonHak6MC/Qb7vkCD+n6mFpwhmyl95FV1iT a6jytr4YjcqnlvHAZDjxVaxKkgmytzjWQe38ZTOk2+wf7TVYIomppWwMqPDTdmQ3PVC/zg gvc2rSkHWyJKpWTwcFKTaL9FtgRfHME= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TDR2Qbrp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3Kk9iYwYKCHMXcZUViXffXcV.TfdcZelo-ddbmRTb.fiX@flex--glider.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3Kk9iYwYKCHMXcZUViXffXcV.TfdcZelo-ddbmRTb.fiX@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667387179; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GIr2ezHJZytLhlXMK2PvYo8WU5NrIng/zb7hVbc1Lzg=; b=o9ZzhJmJ5uLG/7IIRu2V1Fco1604clQbCDFaz4WTxXY1H6YJtt8xZ70V6//qgA+9FRlTTI lf7t9rltb4bAHE2FTTuDJYgZQXnQMYVrvVnurWj5UjAg444jx6MshtnUxfe516WnQIgSrS jwjKigjVcXvcdOa0MlwEt4wi8tlTC7Y= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TDR2Qbrp; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3Kk9iYwYKCHMXcZUViXffXcV.TfdcZelo-ddbmRTb.fiX@flex--glider.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3Kk9iYwYKCHMXcZUViXffXcV.TfdcZelo-ddbmRTb.fiX@flex--glider.bounces.google.com X-Stat-Signature: z6crasynec3buwfd5mk61p69exxqcg7j X-Rspamd-Queue-Id: 3220418000C X-HE-Tag: 1667387178-457312 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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;