From patchwork Wed Nov 2 11:06:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 14177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3555472wru; Wed, 2 Nov 2022 04:15:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5y98+46dh44p06iTX7hQECJVRWki4QqhM4AX+IAS2V81CVCU1R9ETaTfAr29UU2TTdageq X-Received: by 2002:a17:902:cecf:b0:187:fd2:79c3 with SMTP id d15-20020a170902cecf00b001870fd279c3mr7862766plg.34.1667387708191; Wed, 02 Nov 2022 04:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667387708; cv=none; d=google.com; s=arc-20160816; b=yCORGu/dd1WkyOUdWNHsr71qSJbKEOq+Z4i65sP5kpmUBHAbHIKJL9z1SNGzvYYbWD hcj/Ry+Qnf7ied9kLAzNRq9j9wZx48uPsRNah2eB9RkIWC+4RGpEd+n7pNk9sbCTpO2h wtaUk8uQ9KY21r1yBF/xPgaFGXALld2Ee8ttHb5tj1ndZSJSLKicZqPargPu6iEPW1qi nWDuoG3AeGLCOLISNsq9VfPH0roMQPjjFiX3m7PM7rvO7ui4C0+BEgZFCyNEJQnsRmiX hE48G/6pmVxaoB8eHT/xMmAq0IBhll0Vswav1+cRGb+yBAIUC5gynrovKRxy6TDrMw9g oxog== 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:mime-version:date :dkim-signature; bh=ZbeyMEB1N3HnW3KuOlIdq7/dvvJzr15HTa/zFi9USr4=; b=ND1GWQ2TJjirQ07Mtktqlt+EMpyjVMoCEcPehcd7970QU4bwoKao5M1CiouPLltHZE 0kZWx/Txy1PsBanfJGW30vg/Nl2eUL1H0hoQTwN//P0gizXWKPjkf3Vs4QvFVB4o6iMu LFgnYdSV85mGeGpdKtlcOiuyn8QBPE/ReRbdR6qiv8DAnOahfqnT+YqPB91qvzYOAee9 +6eYg329hp94HDYuPvSkCtlZUbGuq2T2t5EBLHD5rPaYYaipU8fFekQaIrZ7m7Cnp2Hd II9eS/509foZsWfmYXio9a3iJDu2u2QpKYP+wzF6RzhsN3FPFMy3u3zdelI2WsR+ioEN SQpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Zys9RxGx; 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 b13-20020a6541cd000000b0045160a30fcasi15617313pgq.388.2022.11.02.04.14.56; Wed, 02 Nov 2022 04:15:08 -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=Zys9RxGx; 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 S230294AbiKBLGS (ORCPT + 99 others); Wed, 2 Nov 2022 07:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbiKBLGQ (ORCPT ); Wed, 2 Nov 2022 07:06:16 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3188824945 for ; Wed, 2 Nov 2022 04:06:16 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 204-20020a2510d5000000b006be7970889cso16185960ybq.21 for ; Wed, 02 Nov 2022 04:06:16 -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=ZbeyMEB1N3HnW3KuOlIdq7/dvvJzr15HTa/zFi9USr4=; b=Zys9RxGxneSiAkiaMSLp0fMMah4Q4Z9cQekcJkJNg09vNC8uJQw/eYHIdshUK8sloS ooGakxYdVsGGFtO0vf+eL1zU+0H2llK4TNEmcMhroLHzQrTPZfBWQDBojDOhblkUEr4Y VlVIHNHQhO38wMiB66DPLA3LFQdtHMrbm5ZhgUQeygogmoqNQKhuvL5oPo0DAC2/5AVe qCxhIyoFmRsOF+cCGGErqjcW2MS+JPt+pV98fCT/Hsinr2F1udxrRJ8ikXkJHQoEIYa3 nXngezqkGCOS882wdt6JuoQoJ6omP88TBbF3foaf3Ou/PIbwm73m0hBRCxKUIYBtx6df B0dg== 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=ZbeyMEB1N3HnW3KuOlIdq7/dvvJzr15HTa/zFi9USr4=; b=aeaVomlXtA/VenbrXTONU+mIhkhBODY+4e6BfFjvk4Avk4/CN+GgGc81DV4W9Q/dHT yzRLydT6CJbrshE3tLJ18x3W77otuMCUHN0SnRjTfGsCdkhrhXaywyd+FPAMLFVRWxlD NMmbX9ySsQ4za8RTG7BB6KUy2k9LyP0viC5eq1njpqOtDZkbECo5Y/hDnZs7pao9HyDq 4fI9RySfj7zdJwp6+FKqV44Xv+zD2KtXzXyU30bSE4D3LQJxnVBcaBAjIhd6F7bWPXPi QKAfAeLZ3jzyS/FJwA4jYFxsKvE2glLcIhR0vXTSdAV6gv81V4djRvp7WnucusJMfFGs SJhA== X-Gm-Message-State: ACrzQf1hkDPLOla0UJmcpRomsbJpTvaG7m1MskjRubLkunbrv7xu5She 02SbipwjNx0mH7zHckLczHWaHcTHekU= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:7f41:af20:8:a96d]) (user=glider job=sendgmr) by 2002:a25:2187:0:b0:6b0:1abc:2027 with SMTP id h129-20020a252187000000b006b01abc2027mr22399213ybh.348.1667387175509; Wed, 02 Nov 2022 04:06:15 -0700 (PDT) Date: Wed, 2 Nov 2022 12:06:07 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog Message-ID: <20221102110611.1085175-1-glider@google.com> Subject: [PATCH 1/5] kmsan: core: kmsan_in_runtime() should return true in NMI context From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Dmitry Vyukov , Marco Elver , Peter Zijlstra 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?1748382733273798899?= X-GMAIL-MSGID: =?utf-8?q?1748382733273798899?= Without that, every call to __msan_poison_alloca() in NMI may end up allocating memory, which is NMI-unsafe. Cc: Andrew Morton Cc: Dmitry Vyukov Cc: Marco Elver Cc: Peter Zijlstra (Intel) Link: https://lore.kernel.org/lkml/20221025221755.3810809-1-glider@google.com/ Signed-off-by: Alexander Potapenko Acked-by: Peter Zijlstra (Intel) --- mm/kmsan/kmsan.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/kmsan/kmsan.h b/mm/kmsan/kmsan.h index 961eb658020aa..3cd2050a33e6a 100644 --- a/mm/kmsan/kmsan.h +++ b/mm/kmsan/kmsan.h @@ -125,6 +125,8 @@ static __always_inline bool kmsan_in_runtime(void) { if ((hardirq_count() >> HARDIRQ_SHIFT) > 1) return true; + if (in_nmi()) + return true; return kmsan_get_context()->kmsan_in_runtime; } 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; From patchwork Wed Nov 2 11:06:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 14181 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3556017wru; Wed, 2 Nov 2022 04:16:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CormpLyCNq9mTPOOZjiT2E29Rw6So4f2nDF4rz3IWeH0ZNZfMjWsRdcUMHDesDrOnJ9vN X-Received: by 2002:a17:90b:1009:b0:213:9716:20b6 with SMTP id gm9-20020a17090b100900b00213971620b6mr24512039pjb.57.1667387763344; Wed, 02 Nov 2022 04:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667387763; cv=none; d=google.com; s=arc-20160816; b=Pc7frv1RmCqp/PCj+IjzBmpxVSyy7fdVb8Euepwu3ZX+Og+ShAibOqySzcnSAEMW0m 3j/jUk6nVPrWFQpbOGh1hMXY/+JgD147jZJ0tmNWv8xyw9uZy+fs2If93o3JgrdzNA6/ TROAexPnFQ4tX/0NzG7ua4N6VGG5GtVqaT/UqqvnI8fvcK/3CNY97FL5ErIiqyJEwvju Cn9y3hDH4HzqqlY2FRvH5rXg7HjjjSSGvRAt7m6hDxtVbeJtIV/3Ki4z26oyySnzbhtk lxcDfunq3P2Tuct3yQ01bO4RlIqUR9nKspyHNJbTm/iME+yobLsWox72sf5+0H2mJl3U R2Cw== 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=fUQfvgq1r8lF9rRRm4NumpIHqFvDpVd5cUWloyxUIys=; b=QC0xr+Z1tXS2Ubx2WdU/+0AT3XDj/0lpYQHcaifDb07UW0CUyvtSD19WlSxixtheqV HuB6YrHEvP4Kp2tHWF/LKlBoge6RKRYgo8w8lGTbaDCd/BPcUYJbGNgp/4P6VLmn+TXy oFXT767NNWK0zc5PqXJA8scWTZZaY+lM4MF3yxC2qbcx4Qt2a2a9wDb7OtqdOAWFnSHO tBR23T5qZSiXoyNxkU/2okbzAcHRT98qo6PbNotPJ79Pv0pQP1wEEYgxW9JwbnfFjhqc gM/3qo44YBHZKkAThLVwKH6CEI8iOkcgL0Gamy4gKylFU+ER/ppK2e6tATYajZYws22F 0cRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZOFvSA0c; 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 28-20020a63125c000000b0046fabcb7bacsi12147795pgs.823.2022.11.02.04.15.50; Wed, 02 Nov 2022 04:16:03 -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=ZOFvSA0c; 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 S230338AbiKBLGe (ORCPT + 99 others); Wed, 2 Nov 2022 07:06:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbiKBLGX (ORCPT ); Wed, 2 Nov 2022 07:06:23 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FE7829372 for ; Wed, 2 Nov 2022 04:06:22 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id b13-20020a056402350d00b00464175c3f1eso160397edd.11 for ; Wed, 02 Nov 2022 04:06:22 -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=fUQfvgq1r8lF9rRRm4NumpIHqFvDpVd5cUWloyxUIys=; b=ZOFvSA0cmseSVYIuYaM2BdEV+9xbe5Xbf2t7D0GgypSpP1gnX3wIZjxGtpGcZlix5E FCdURGEXcoZhbn0atFQBOKA8PWu5GZmM0PepNS7WW/UOv8wS8UBvhYQA/S017ZeMaU6B pduViuSKslfAwUv/JkReNhliQybOgcLy8uFrc0LLbfBUiBcHAE6KfsJe1A8kD7TZje6B IGivUc1aeRKlICNXfm5j+lzmy+rGqkvLo+gUkMJchlsBDJTqDJ/HltB0c5Jh1EmtZrYy udfceaJkn1m4l67dY8Nrhn/+bADs62+zBKdKM2OPoBBpBSlwpT6u6Adqi1g1JykfTIHV nquA== 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=fUQfvgq1r8lF9rRRm4NumpIHqFvDpVd5cUWloyxUIys=; b=5Wku6TgvF03ZuSfXqeKpwDXKmkI4IZQRVl7Jelp/SDs3xVubXm2ptEE2eOPyFOJBYv GwcPwkGvVknbKP0MLZKhdGxL1KxkwB4J5PiWy6hNvPckG76eAgeRQHXATFFKmaIeqzKb G2o0d9yUm/CKRN+MdrZd0cBMNFLWMjiYaTIz/j14ay+3KL6oS2XZIstMyTIaMxsY0IU/ +XIXaXz2prYJDNCorYgN4T0Xjh++FMohVcgA0yseYbKnLUiOkIZWmX4H1pfZiWLflzkj qxkHgljz17qg33cqfcU2tj/KqBji2/RV8fYDFIJMCBJcigxneZjg1R3C/76bUaY5Tq5J 7RSQ== X-Gm-Message-State: ACrzQf1OBpEGVLFemuY0Hv/Yf8B+HcVE7yTYBolQwmDrVGt+5pi+d7Da krES3y3RC6R9ok72PA8iDqCe69IQSEU= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:7f41:af20:8:a96d]) (user=glider job=sendgmr) by 2002:a05:6402:450c:b0:443:6279:774f with SMTP id ez12-20020a056402450c00b004436279774fmr24423763edb.11.1667387181029; Wed, 02 Nov 2022 04:06:21 -0700 (PDT) Date: Wed, 2 Nov 2022 12:06:09 +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-3-glider@google.com> Subject: [PATCH 3/5] Kconfig.debug: ensure early check for KMSAN in CONFIG_KMSAN_WARN From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Kees Cook , Masahiro Yamada , Nick Desaulniers , linux-kbuild@vger.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?1748382791305075336?= X-GMAIL-MSGID: =?utf-8?q?1748382791305075336?= As pointed out by Masahiro Yamada, Kconfig picks up the first default entry which has true 'if' condition. Hence, the previously added check for KMSAN was never used, because it followed the checks for 64BIT and !64BIT. Put KMSAN check before others to ensure it is always applied. Cc: Andrew Morton Cc: Kees Cook Cc: Masahiro Yamada Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Link: https://github.com/google/kmsan/issues/89 Link: https://lore.kernel.org/linux-mm/20221024212144.2852069-3-glider@google.com/ Fixes: 921757bc9b61 ("Kconfig.debug: disable CONFIG_FRAME_WARN for KMSAN by default") Signed-off-by: Alexander Potapenko --- lib/Kconfig.debug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 29280072dc0e4..b4a0988a7ffd2 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -395,12 +395,12 @@ endif # DEBUG_INFO config FRAME_WARN int "Warn for stack frames larger than" range 0 8192 + default 0 if KMSAN default 2048 if GCC_PLUGIN_LATENT_ENTROPY default 2048 if PARISC default 1536 if (!64BIT && XTENSA) default 1024 if !64BIT default 2048 if 64BIT - default 0 if KMSAN help Tell the compiler to warn at build time for stack frames larger than this. Setting this too low will cause a lot of warnings. From patchwork Wed Nov 2 11:06:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 14182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3556080wru; Wed, 2 Nov 2022 04:16:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RppXsG14x0q8ljQCi16x2r+tFCDKice1j1WYpaXbMezO0bUTQbOj1McEkT3XdKI1TycIT X-Received: by 2002:aa7:809a:0:b0:567:6e2c:2e2a with SMTP id v26-20020aa7809a000000b005676e2c2e2amr24941893pff.56.1667387771885; Wed, 02 Nov 2022 04:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667387771; cv=none; d=google.com; s=arc-20160816; b=hAgTmtSXqvO2Yxmzlw4g0MP32HL/JL28Hzk41iHJbEWWM/z6Zi4MWdV1M145f/VvXM qkfx8oZgAZ4VcASoa+iY+Zj9dBqisJxyGV+SGddsaGELyOwOCrFX0btnshDs26OajHxF jKRSu/3fI73sABB/oWLa7nMkFir0Qe0TtmzakK5rviNlEOxuJZgjnobLqayziqTlgs/q UE+Ev1J4ojgwMI6fq9OHsIS9OAGc6qSZ11SVhBxkhYDTWuZxXVoUQ8iTM6SCAwSfeAji Q6g5KEFdbb4GnYCHKw0tg8a67qAimiYNt57vnBR5dLe3DBqKImyQjaGXaCpy3kRfig4m FzWQ== 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=WrClR7h0c/XU2pAfJHOZckEycFJJtsgVk0eEUZJfByQ=; b=vjzWKfyBHFTIcpXmAyVu3omzaAB4Q+VO2j4O320ebQ1X+//qKBRxY/pqeFauDxV5sc j++u8EKsEw5Gy0ZzdsUbv7hbq40128/+UUW16myl5QB4rJ9mJSpQJpRFkRE2jfnj+gno zSqx0DL2b4WSE/iphQd9eKgWgr6F9LVrzpoSG15vcZzgWa4bupWfeJkIbKelJ05MsUMP Mjt740VBgPXxFN3NerBlT7QbyP8vvo5dF61OMJ58OOR/0Ko+YVXlX4sgP/UXrEkRRVIS 0DFI3MNUVSQu0OEJ3UiHHeImym0EXY4D7oOox4UoJ+Z/Ef40A+FcbJmPVmojMca1PnAZ cTew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=p8C9Afvz; 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 lr18-20020a17090b4b9200b00212a866de99si2113071pjb.157.2022.11.02.04.15.59; Wed, 02 Nov 2022 04:16:11 -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=p8C9Afvz; 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 S230451AbiKBLGg (ORCPT + 99 others); Wed, 2 Nov 2022 07:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230370AbiKBLGd (ORCPT ); Wed, 2 Nov 2022 07:06:33 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2826529C83 for ; Wed, 2 Nov 2022 04:06:25 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id d23-20020adfa417000000b002364a31b7c9so4682909wra.15 for ; Wed, 02 Nov 2022 04:06:25 -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=WrClR7h0c/XU2pAfJHOZckEycFJJtsgVk0eEUZJfByQ=; b=p8C9AfvzfTHb4amAZyR7Huo6iTM2OmZ596wuVutv4RMIjPVHhzGcRhijW0Wdzbgz/4 mg8h+O0U7SL3esE9xQvb/5kztONm+5qgbpw+tJlE//0bLZKuFkjRAzzQj+0wx1PDrFL6 Gauls6F4ST7RPiHkY++x7dd+3pFWOzDJv/RKpYF7ClI+YHFIqhcGVGIZOl7rqs/xFadg JoL4S1a87PsVKKh6JjnOfr+h9u34ulSYmsJAwMO91rHcN2Iy4iWb7e3lSQdY6fNFQ1ky oJ0NvFIbyshMi4t2Q/NN65+FNBXzM8tc6cSwn+oFCnYObruLNwf8GKhvRyngWCXgMNCu nieA== 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=WrClR7h0c/XU2pAfJHOZckEycFJJtsgVk0eEUZJfByQ=; b=Fkj0wGbRuEOzGfSMKkuwKKydff6CpzFQgzN+ABOsco+lsN+/OBObvfeE/pQVFWvRm4 5y4Lhw0/ItsNDIHDyQNaW8MHSV6tEjgWhrhKjtjRfDGhFZjGyTFnvB5VeaUEfVrv+D4p 5QmPyO8NucyM61/YSccjz/RNvxCn8pWywjUAgBzygJycqxHysH5ukGgGG9W/EWrA5Kzy 8iUIARPwoKBLu1YmPhkhl4pM6+eXOVmAcgd6AWoVcxvzMTPxEcApc4vp0SghGeWMBY94 FzP1GxPtJaxXuxCU2HArjkqkq7vif0hrQDg9X9WcHl3SpWBLjASbdj935PeAHs69AAqh 9ufg== X-Gm-Message-State: ACrzQf1L0yr2EGljHpuQwcsMlyfb7UEpVyBGqZJ2EaG08L6Z/TK4HRQJ +cpdUGfYE/AdNKOpAtIv3lvFYwZtG7A= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:7f41:af20:8:a96d]) (user=glider job=sendgmr) by 2002:adf:dd91:0:b0:236:a261:6930 with SMTP id x17-20020adfdd91000000b00236a2616930mr14444934wrl.551.1667387183641; Wed, 02 Nov 2022 04:06:23 -0700 (PDT) Date: Wed, 2 Nov 2022 12:06:10 +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-4-glider@google.com> Subject: [PATCH 4/5] kmsan: make sure PREEMPT_RT is off From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Dmitry Vyukov , Marco Elver , Peter Zijlstra 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?1748382800242290895?= X-GMAIL-MSGID: =?utf-8?q?1748382800242290895?= As pointed out by Peter Zijlstra, __msan_poison_alloca() does not play well with IRQ code when PREEMPT_RT is on, because in that mode even GFP_ATOMIC allocations cannot be performed. Fixing this would require making stackdepot completely lockless, which is quite challenging and may be excessive for the time being. Instead, make sure KMSAN is incompatible with PREEMPT_RT, like other debug configs are. Cc: Andrew Morton Cc: Dmitry Vyukov Cc: Marco Elver Cc: Peter Zijlstra (Intel) Link: https://lore.kernel.org/lkml/20221025221755.3810809-1-glider@google.com/ Signed-off-by: Alexander Potapenko Acked-by: Peter Zijlstra (Intel) --- lib/Kconfig.kmsan | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Kconfig.kmsan b/lib/Kconfig.kmsan index b2489dd6503fa..ef2c8f256c57d 100644 --- a/lib/Kconfig.kmsan +++ b/lib/Kconfig.kmsan @@ -12,6 +12,7 @@ config KMSAN bool "KMSAN: detector of uninitialized values use" depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN + depends on !PREEMPT_RT select STACKDEPOT select STACKDEPOT_ALWAYS_INIT help From patchwork Wed Nov 2 11:06:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 14183 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3556088wru; Wed, 2 Nov 2022 04:16:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5nYzT0Zi8Yj+ky3PwhQrHebqH8PkR51M0DkmHu/ZfWIKcO0SkODILGO7JLcSsdAoGCJeBo X-Received: by 2002:a17:902:e902:b0:186:9c03:5f27 with SMTP id k2-20020a170902e90200b001869c035f27mr24166874pld.16.1667387773082; Wed, 02 Nov 2022 04:16:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667387773; cv=none; d=google.com; s=arc-20160816; b=0uIb2LVjx9VHzT3Cvuk1M+hvMkO4/glOg8cw3XsM7pWjBNmgC1HjpytJQLPEqBxQ76 qRs7CHlANES15y0fVzmaaEmhFD0pd5nVpTz2g+kYEcltIhjVxjgOj+9yOw1307ekjoJ5 Ds72+efTnbMMpIuKH8P3NUn3pSeRQmfn7ILE1RNNtrSxp5/n6rLG1MtIiJxetdcSbsOh Wa2qYQOVyNwGhTfPBzvZGzMgWVlS9X/FIEDWq1tIJVcUb/bCIIimAFtcNDdRrD4+0G6T FVbBe+vjBM/dqtjt07U0bJrJ1xVS6Gmpq3UgW/G2SQ0pl2FNgc5WQl/Zto9IgrW+bCJb nhjQ== 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=Dk/dhHPL0qFVshysQ/N4gnrAp81kLluhRpZpiN1N26A=; b=yx1xEGBf3+YktoU4198hAGqWMO0M4TZF64VQh8s2+lOJHzIJp2UQ2ztc10lffkPbt/ s8L7b1uFRdFD4X/tO0vd/bwwoYhabawDF5hV3pjAJz1cZJiUkxR671O417a/05g2kynX HHwDG8ZfES8fbvFY2ObvIKNrfcO04HVDxMJTASvxhSKyVUiBX50w+8HlN8PCK32SF70F ljohVCdFLwJfO82dPJ5O661TzhtLSd1IOPNKHtAWQM1eR2Iep1XC5Rk3s2sAoOftEV+Q uvj/duR8Hb2OSjFmKyYiUBk8sRxw9Up2nrW6jYwZdTokfIMJdtyQvKre9hgUExMdQvqu tsyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BRXuAvLO; 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 n3-20020a17090a5a8300b00212e738ac60si1877815pji.84.2022.11.02.04.16.00; Wed, 02 Nov 2022 04:16:13 -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=BRXuAvLO; 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 S230302AbiKBLGk (ORCPT + 99 others); Wed, 2 Nov 2022 07:06:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbiKBLGd (ORCPT ); Wed, 2 Nov 2022 07:06:33 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F9029C9A for ; Wed, 2 Nov 2022 04:06:28 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id v18-20020a056402349200b004622e273bbbso11777352edc.14 for ; Wed, 02 Nov 2022 04:06:28 -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=Dk/dhHPL0qFVshysQ/N4gnrAp81kLluhRpZpiN1N26A=; b=BRXuAvLOHF3g9+gYxk6eLf0iLGvj05paMev0jUBgMnN/5twd8iGLllzv5YJfGiXvxo bbpa22yuLIs03sydQwA6d6FHWh1ns4oA9GlUYXwh/RQbSpseclTQoxYM356MlrCxyM/d l7xAksNUDe2qS9tRUGAgfy+pCWc4utGI5Aty2dyjLc/3QuuQjIB0MOtKWoWhtakZ6Yli rzVdmRwM0RTjlvJ/Zf6eD8WP9SwZrTA2aldlm9B/FxucwGXrXuxw2IjQDm4QRRrggsYe oNPE1SV5IP9wsvvEx/aHSu69q3tQhoACudVb+Jy9nLyKvCVO3Fknl0VsdVPh0u+lG1Ta aVsQ== 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=Dk/dhHPL0qFVshysQ/N4gnrAp81kLluhRpZpiN1N26A=; b=TElqPd5Npt1rUPN5Kuxr5T9TD7OkEcegoxFibIKREEkDY2W7Z0t4It0QBf5R1Lh0Z2 MhQdqeWKgAvu7+xaNvOxgMTWKqGQL1Mw+jwgpTB9I2N9YhLbFKhXaPiGUAWTPI3ZGMyS qf2864yDg5RmM3mbdbxNDRRq50PE7MuVv4L1AqMhD4dKta7we73OmOaEGzmpNwguxNJC ydKxI7ic5eQrv89bA9b9kOLshPo0bLUqJFAOdjyGykXNQcGU8mxQ+k0K1oAnGzsYemEJ pLqitAOZLnUDbkDw3KoquEnZYkhhQE8Cx+GbvwaYZc0LULx4PLqmkBLPYYOtWt99rzwB /lwA== X-Gm-Message-State: ACrzQf1dlAUOmR9kWRWL0ZKHMgy1Pb336soJoPpSWCJiKh2xU3Wn4fjx FQfUnrpZs+GNAZrJLQzhoZ/PDUmQAIM= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:7f41:af20:8:a96d]) (user=glider job=sendgmr) by 2002:a17:907:a80f:b0:7ae:3f7:b612 with SMTP id vo15-20020a170907a80f00b007ae03f7b612mr2514087ejc.421.1667387186488; Wed, 02 Nov 2022 04:06:26 -0700 (PDT) Date: Wed, 2 Nov 2022 12:06:11 +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-5-glider@google.com> Subject: [PATCH 5/5] 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 , Thomas Gleixner , 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?1748382801674461265?= X-GMAIL-MSGID: =?utf-8?q?1748382801674461265?= 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: Thomas Gleixner Cc: x86@kernel.org Signed-off-by: Alexander Potapenko --- arch/x86/kernel/traps.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 178015a820f08..d3fdec706f1d2 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -301,6 +302,12 @@ static noinstr bool handle_bug(struct pt_regs *regs) { bool handled = false; + /* + * 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); if (!is_valid_bugaddr(regs->ip)) return handled;