From patchwork Thu Nov 3 13:45:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 13030010 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 D76CCC4332F for ; Thu, 3 Nov 2022 13:45:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BC566B0072; Thu, 3 Nov 2022 09:45:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56C106B0073; Thu, 3 Nov 2022 09:45:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 433886B0074; Thu, 3 Nov 2022 09:45:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 349546B0072 for ; Thu, 3 Nov 2022 09:45:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F2CE1A0105 for ; Thu, 3 Nov 2022 13:45:41 +0000 (UTC) X-FDA: 80092253682.28.EA99ACF Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf29.hostedemail.com (Postfix) with ESMTP id 5CA6012000C for ; Thu, 3 Nov 2022 13:45:40 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id x18-20020a05640226d200b00461e027f704so1410066edd.7 for ; Thu, 03 Nov 2022 06:45:39 -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=ScuUET3Jx3790WWtzDciWGjRGXPi9X8ISFOvBcfPIsI=; b=leCGMG1Ihb72GuqEhvKiIBXP3svrLi4GzMCcHOGP9PM8igal8vM5W4lXCqnNucSw3P 1fnQ15L2ZK8WgXHhy3OiPjE01iUPYRYjn+HLa1puFmYg6oh4P8+TsU59MFP97mWSj9Tp /GKp7HOeM/hBv8kUjeXHmP7yGCPjf5B8kOAo47zvM3+0u2Om3tQyaR9nGEpB2MOY4Aqj Y52eQAHsh/vMHHfCqhKOhQy4lGBB+wvxc9rt8N02K44QPooSfTBlbkqMBHldPPxcCiIP LS9pz4lZ2ruUA+NsjYpnhDCoLsQW3eMQvtR8LhsOJPoSnCydWfm6Zg1Hgi5CiuaqUFhQ mYkw== 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=ScuUET3Jx3790WWtzDciWGjRGXPi9X8ISFOvBcfPIsI=; b=8My/CgRKzunsGEhrByMdhOr1tWHIjJNv1fRqdwRRffihbsAepqJgI2qzsGtqQh/0zI Ci2hAjflWxBCxjJ0ghwUlmINoGxokIFxwvwaCN7jaSdYBxBNABPw4k/24R4sx2mEAN+u ENL3/ZvL7JmRzOqZLw5MdOryEQEiqeS+UCZhak6dnwCnUypb2Sl/obgM/wcsSJjHhHOo lAuAsB6SsbwkkqOtnAGnx4xyFbSOzynwMYFZ6kI6VxhIas8jdDgQ9IbBpRjd+XeF57vb mMdr/Ir3ExuKigSj8qg9oEUx4D8h3n2EqxyjstmbJJoF/K0qhTRViIDl3WV98DXyRRZH fSvw== X-Gm-Message-State: ACrzQf1dEzj+keY7R0gsJEiJWd1gggvgT0ut+1wh2O2oE7r63javrsqp 8iOitluao3PKBFR5jFdcwjmiVwjfOzo= X-Google-Smtp-Source: AMsMyM5txHoDUQHV74JbL/I6drhqJzAVd4b0cSj6OCCI9DN1HmElG8LQngrwgUKWVyAIdwt42FAiHVc9R6A= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:f99b:157d:615b:bbd8]) (user=glider job=sendgmr) by 2002:a17:906:7d8c:b0:7ae:159d:1146 with SMTP id v12-20020a1709067d8c00b007ae159d1146mr3887934ejo.528.1667483138558; Thu, 03 Nov 2022 06:45:38 -0700 (PDT) Date: Thu, 3 Nov 2022 14:45:15 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221103134515.1934867-1-glider@google.com> Subject: [PATCH v2] x86/traps: avoid KMSAN bugs originating from handle_bug() From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Borislav Petkov , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , x86@kernel.org ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=leCGMG1I; spf=pass (imf29.hostedemail.com: domain of 3AsZjYwYKCD8hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3AsZjYwYKCD8hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667483140; a=rsa-sha256; cv=none; b=Rwz+qi7yIG/u6eobk0N46ind8+tAwQjuoBMILHmjP52ZZzHRw3qYSjsZ4QSKz5WYdpPB4X 83ivnb87pxIKOb5v6CLCMicQK7geR3IAUg2lcFzQVLL5VrZ/x0xhepLnQGSklhuLxSPmim 7NhKpY0YfBxRPvNIQj2xDs+z+Di15Po= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667483140; 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=ScuUET3Jx3790WWtzDciWGjRGXPi9X8ISFOvBcfPIsI=; b=jap0vLn6bboNm3m0t2rN+qmq+YAUZwtQfDc9w6USN6g2t8GxJjb960pDWRlkibeo7pADQJ UlwrZDBdmEAZa+2YDHxSfjL3SdEUPG+4JClJ2sODWPUAGbWwlED5uc7un8vHU9luAztFIm 3ECcmEirsWYfIg24XMRu5apKmOeHjEY= X-Stat-Signature: ppeodj9kz9cus577fpcxs9n9r1yz34bk X-Rspamd-Queue-Id: 5CA6012000C Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=leCGMG1I; spf=pass (imf29.hostedemail.com: domain of 3AsZjYwYKCD8hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3AsZjYwYKCD8hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspam-User: X-HE-Tag: 1667483140-957874 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: There is a case in exc_invalid_op handler that is executed outside the irqentry_enter()/irqentry_exit() region when an UD2 instruction is used to encode a call to __warn(). In that case the `struct pt_regs` passed to the interrupt handler is never unpoisoned by KMSAN (this is normally done in irqentry_enter()), which leads to false positives inside handle_bug(). Use kmsan_unpoison_entry_regs() to explicitly unpoison those registers before using them. Cc: Andrew Morton Cc: Borislav Petkov Cc: Dave Hansen Cc: Ingo Molnar Cc: Peter Zijlstra (Intel) Cc: Thomas Gleixner Cc: x86@kernel.org Signed-off-by: Alexander Potapenko Acked-by: Peter Zijlstra (Intel) --- v2: - move the call to kmsan_unpoison_entry_regs() after the instrumentation_begin(), as suggested by Peter Zijlstra --- arch/x86/kernel/traps.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 178015a820f08..66701b4d99acd 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -308,6 +309,13 @@ static noinstr bool handle_bug(struct pt_regs *regs) * All lies, just get the WARN/BUG out. */ instrumentation_begin(); + + /* + * Normally @regs are unpoisoned by irqentry_enter(), but handle_bug() + * is a rare case that uses @regs without passing them to + * irqentry_enter(). + */ + kmsan_unpoison_entry_regs(regs); /* * Since we're emulating a CALL with exceptions, restore the interrupt * state to what it was at the exception site.