From patchwork Tue Oct 25 22:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13019941 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 52045FA373D for ; Tue, 25 Oct 2022 22:18:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9D5A8E0002; Tue, 25 Oct 2022 18:18:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4D978E0001; Tue, 25 Oct 2022 18:18:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 915698E0002; Tue, 25 Oct 2022 18:18:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7F33F8E0001 for ; Tue, 25 Oct 2022 18:18:02 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 46BEA40E73 for ; Tue, 25 Oct 2022 22:18:02 +0000 (UTC) X-FDA: 80060885604.13.4E25C6C Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf18.hostedemail.com (Postfix) with ESMTP id DADE61C003C for ; Tue, 25 Oct 2022 22:18:01 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id go14-20020a1709070d8e00b007952a849f71so3512623ejc.11 for ; Tue, 25 Oct 2022 15:18:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ZQGssT3M/U7b4XMGY/asVcg61n5AcupNDo7Gu+AvRuY=; b=GZzG9I3EC4BdTG42DnBMyd1ivXSjjTelzZgMfx5pqBuLbH+hAXxGKOtyb79pJSdisX /cpLkpV914ei9LOOwDEcu7sTj/B25/nINBuG35/Tk8G54bHHoc+ny2ycz1Wam8uSNmGd tY/cb0kPSQi17ZqKRk4v3fjjk3EuSGaByehhMseFU4VSIV3fseJw2rBBP+T7eVNHsmf0 tVDy8K7dQhxLyCes+qB6UaAS/ALtPRdJJfJCqOT8iExcL/IzM25Ullu5r3UeNdoSZqBy KYA/w+Zg554ckMQspY6Vt30Ly/d4YYC5g2WsdbKbuwghxsCBeOYps6smx3sA2/cHwrxs r7qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ZQGssT3M/U7b4XMGY/asVcg61n5AcupNDo7Gu+AvRuY=; b=jGTnfxOUFEmpqCD/lABCnD/0+wU/sZ7xrmqoQd9DjnKIQsrT6ZSBmkuWtOYo9p2Vp+ M+AwWo8U6JVERfO0TAaJy4ZgOMYu7u2Yn3YjnDTmz+b1gGZhiwEFc0mszLB5B+4uD6P/ BHlRc5FjJJUdm2ge+Fo6ftipsRxpXPMPX//bBfqD5jm3j2DZI/klQQ1QXBGKBxu96TM5 8vE28ITxawcHlIsLyWKra9g+kuks7p7FQP1p+FHUDxHUEjVlpUAUdVHyUv224j+txszG ESEbEPQdqeZSqxh8ZY2H5V/6AqurkVqZ4yidIhOzKVzyJahIAZeZwgf7+DW3r/158Aam J7eg== X-Gm-Message-State: ACrzQf2ba9FZSLQ+K1CP7eDtN8qllOTKrNP6dO2uLvRs5idqEubAwaRu 0JkDC484msoXe+C1nj+O9w1f+zLFYEM= X-Google-Smtp-Source: AMsMyM6wWRQeoGnTklgT6+h+msVouxh/KVCK+QWxO1G7zXpVRcKJfnF95EwBt0uYbBEf2yxO5HMusq31MdQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:2e8:4dec:7a62:7bda]) (user=glider job=sendgmr) by 2002:a05:6402:b2f:b0:461:701e:877a with SMTP id bo15-20020a0564020b2f00b00461701e877amr18471401edb.82.1666736280249; Tue, 25 Oct 2022 15:18:00 -0700 (PDT) Date: Wed, 26 Oct 2022 00:17:55 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221025221755.3810809-1-glider@google.com> Subject: [PATCH] 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 , x86@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666736282; a=rsa-sha256; cv=none; b=OzQRWBqvK1vHj7jq/X2/ttLc20e09JCmrYjvMb+o7Lt8QcSzKnwF2U7DdAAJn0N4m5H9KP u23Qb2awND4CpdC2TRylH+nF0zZL9v4K7i8hIIjzn0W4aE4uGiQTI28oWZO6sp3hl3Fx12 Lc6GxjyCDe4EqHuBfuDltWt15uz1GSE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GZzG9I3E; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3mGBYYwYKCNsDIFABODLLDIB.9LJIFKRU-JJHS79H.LOD@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3mGBYYwYKCNsDIFABODLLDIB.9LJIFKRU-JJHS79H.LOD@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666736282; 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: references:dkim-signature; bh=ZQGssT3M/U7b4XMGY/asVcg61n5AcupNDo7Gu+AvRuY=; b=h0ldcXVLEiHL6wPnGmzRghOkua9mXt2SyJ2O+01DSCe+15QgyDmajmI0kO5WANzh+bcbSu 3i88pnwJhIwvX77W4idjjhnp4tQVGi0wAq/IqPy0+4sTiBvH9M83snUaUcbJBEZTKKcgG7 oulooKfaJOvBBcZOz642UVnolpfM08M= X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=GZzG9I3E; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3mGBYYwYKCNsDIFABODLLDIB.9LJIFKRU-JJHS79H.LOD@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3mGBYYwYKCNsDIFABODLLDIB.9LJIFKRU-JJHS79H.LOD@flex--glider.bounces.google.com X-Rspamd-Server: rspam11 X-Stat-Signature: y31jnqgo3fe65ngqudm1q77cwq8arpaf X-Rspamd-Queue-Id: DADE61C003C X-HE-Tag: 1666736281-813552 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: x86@kernel.org Signed-off-by: Alexander Potapenko --- 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;