Message ID | 20230306160656.14844-1-n.zhandarovich@fintech.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1971621wrd; Mon, 6 Mar 2023 09:28:34 -0800 (PST) X-Google-Smtp-Source: AK7set8x61ngMXcC7WvfZatLPw2PI3ZD10o+Ogp2DOjFABl/A5ruLf7nq9n8x+/iNdrqeEd7Wwlz X-Received: by 2002:a17:906:d28c:b0:8e5:88ca:ebac with SMTP id ay12-20020a170906d28c00b008e588caebacmr10945939ejb.40.1678123714325; Mon, 06 Mar 2023 09:28:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678123714; cv=none; d=google.com; s=arc-20160816; b=fwmLJ4Bg1P6/q/YtNahbqGz5rEA1VO7jK1ZBXhi43BWYRKBpxdwKJerP8LygXPhh+d wKhzXqNcDHQszDxPNX/nkZ4Oa2HbrbFfM5e6sOvfQju0rn7OIC47srr9eagQTqBxlwmt Ao3bVDQARSvdHbGo6KYOu82TwfwHjuo0pQ8uArggBYVPM9IoihWs+kEznoizk8Exx/5A jgK43vO3xwFZStt3VbkRLQy1rtgUc8ZTwunusjzy86Uaf8hogGzG0L7+bnqT/W9FRNy+ D+0Pt95mZ5gQE0dbxMycVES/6jZzqGFyRCZhAry21yd61NR83NeKZgtIkzcuikTHVF3c B12g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=5Nd5Fb7DZ3E7gx1VnUMfCX/rIeAVNRFitpVQwD7uMGY=; b=Wy9/L7J3yz07NF1zcE1rWQA4ZLTy8SlrtZUOoo5ZRVGOd1Vi39+MY58hKROqeaUBFC FDhurpkiBlpgQM68SNsij+VWfijezioYtOoghn/IjV8dqabPZ/vieOYtUI7t/IKG8wp+ ltFbUWcU34JEdGxaXA/EJgWopzjDbQGwLYfcjS7uI5puDNKdp+U56tZssk7ae1aRnfNa UBOKuNg2m9JKrM2w9V5A2DsoIGiwqP/b0/TQyzWUfm3yMKkEPcK1DBdh/3ZGJB4tanrj 4RRcmI9yGDZTENIZ19lBehf7r22zEUfvXDhQDUWRJxjXxPsc9efu4bpQ/QwArM5lIbcb jIwg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a17090622d800b008e1cbdcd3bbsi761916eja.513.2023.03.06.09.28.10; Mon, 06 Mar 2023 09:28:34 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjCFRUY (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Mon, 6 Mar 2023 12:20:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230001AbjCFRUP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 6 Mar 2023 12:20:15 -0500 Received: from exchange.fintech.ru (e10edge.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405743C37 for <linux-kernel@vger.kernel.org>; Mon, 6 Mar 2023 09:19:51 -0800 (PST) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.169) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 6 Mar 2023 19:07:14 +0300 Received: from localhost (10.0.253.157) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 6 Mar 2023 19:07:13 +0300 From: Nikita Zhandarovich <n.zhandarovich@fintech.ru> To: Dave Hansen <dave.hansen@linux.intel.com> CC: Nikita Zhandarovich <n.zhandarovich@fintech.ru>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Tom Lendacky <thomas.lendacky@amd.com>, <linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org> Subject: [PATCH v2] x86/mm: Fix use of uninitialized buffer in sme_enable() Date: Mon, 6 Mar 2023 08:06:56 -0800 Message-ID: <20230306160656.14844-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.157] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759640252055937182?= X-GMAIL-MSGID: =?utf-8?q?1759640252055937182?= |
Series |
[v2] x86/mm: Fix use of uninitialized buffer in sme_enable()
|
|
Commit Message
Nikita Zhandarovich
March 6, 2023, 4:06 p.m. UTC
cmdline_find_option() may fail before doing any initialization of
buffer array. This may lead to unpredictable results when the same
buffer is used later in calls to strncmp() function.
Fix the issue by returning early if cmdline_find_option() returns -1.
Found by Linux Verification Center (linuxtesting.org) with static analysis
tool SVACE.
Fixes: aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
v2: per Borislav Petkov's <bp@alien8.de> remarks:
- return early if cmdline_find_options() fails with -1 instead of zeroing out
buffer;
- use correct Fixes: commit hash
arch/x86/mm/mem_encrypt_identity.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On 3/6/23 10:06, Nikita Zhandarovich wrote: > cmdline_find_option() may fail before doing any initialization of > buffer array. This may lead to unpredictable results when the same > buffer is used later in calls to strncmp() function. > Fix the issue by returning early if cmdline_find_option() returns -1. > > Found by Linux Verification Center (linuxtesting.org) with static analysis > tool SVACE. > > Fixes: aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption") > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> Acked-by: Tom Lendacky <thomas.lendacky@amd.com> > --- > v2: per Borislav Petkov's <bp@alien8.de> remarks: > - return early if cmdline_find_options() fails with -1 instead of zeroing out > buffer; > - use correct Fixes: commit hash > > arch/x86/mm/mem_encrypt_identity.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c > index 88cccd65029d..c6efcf559d88 100644 > --- a/arch/x86/mm/mem_encrypt_identity.c > +++ b/arch/x86/mm/mem_encrypt_identity.c > @@ -600,7 +600,8 @@ void __init sme_enable(struct boot_params *bp) > cmdline_ptr = (const char *)((u64)bp->hdr.cmd_line_ptr | > ((u64)bp->ext_cmd_line_ptr << 32)); > > - cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)); > + if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)) < 0) > + return; > > if (!strncmp(buffer, cmdline_on, sizeof(buffer))) > sme_me_mask = me_mask;
diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index 88cccd65029d..c6efcf559d88 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -600,7 +600,8 @@ void __init sme_enable(struct boot_params *bp) cmdline_ptr = (const char *)((u64)bp->hdr.cmd_line_ptr | ((u64)bp->ext_cmd_line_ptr << 32)); - cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)); + if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)) < 0) + return; if (!strncmp(buffer, cmdline_on, sizeof(buffer))) sme_me_mask = me_mask;