* [PATCH v2] x86/mm: Fix use of uninitialized buffer in sme_enable()
@ 2023-03-06 16:06 Nikita Zhandarovich
2023-03-13 12:49 ` Tom Lendacky
2023-03-16 13:45 ` [tip: x86/urgent] " tip-bot2 for Nikita Zhandarovich
0 siblings, 2 replies; 3+ messages in thread
From: Nikita Zhandarovich @ 2023-03-06 16:06 UTC (permalink / raw)
To: Dave Hansen
Cc: Nikita Zhandarovich, Andy Lutomirski, Peter Zijlstra,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
H. Peter Anvin, Kirill A. Shutemov, Tom Lendacky, linux-kernel,
lvc-project
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(-)
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;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] x86/mm: Fix use of uninitialized buffer in sme_enable()
2023-03-06 16:06 [PATCH v2] x86/mm: Fix use of uninitialized buffer in sme_enable() Nikita Zhandarovich
@ 2023-03-13 12:49 ` Tom Lendacky
2023-03-16 13:45 ` [tip: x86/urgent] " tip-bot2 for Nikita Zhandarovich
1 sibling, 0 replies; 3+ messages in thread
From: Tom Lendacky @ 2023-03-13 12:49 UTC (permalink / raw)
To: Nikita Zhandarovich, Dave Hansen
Cc: Andy Lutomirski, Peter Zijlstra, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, x86, H. Peter Anvin, Kirill A. Shutemov,
linux-kernel, lvc-project
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;
^ permalink raw reply [flat|nested] 3+ messages in thread* [tip: x86/urgent] x86/mm: Fix use of uninitialized buffer in sme_enable()
2023-03-06 16:06 [PATCH v2] x86/mm: Fix use of uninitialized buffer in sme_enable() Nikita Zhandarovich
2023-03-13 12:49 ` Tom Lendacky
@ 2023-03-16 13:45 ` tip-bot2 for Nikita Zhandarovich
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Nikita Zhandarovich @ 2023-03-16 13:45 UTC (permalink / raw)
To: linux-tip-commits
Cc: Nikita Zhandarovich, Borislav Petkov (AMD),
Tom Lendacky, stable, x86, linux-kernel
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: cbebd68f59f03633469f3ecf9bea99cd6cce3854
Gitweb: https://git.kernel.org/tip/cbebd68f59f03633469f3ecf9bea99cd6cce3854
Author: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
AuthorDate: Mon, 06 Mar 2023 08:06:56 -08:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Thu, 16 Mar 2023 12:22:25 +01:00
x86/mm: Fix use of uninitialized buffer in sme_enable()
cmdline_find_option() may fail before doing any initialization of
the 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 an error.
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>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Acked-by: Tom Lendacky <thomas.lendacky@amd.com>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20230306160656.14844-1-n.zhandarovich@fintech.ru
---
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 88cccd6..c6efcf5 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;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-03-16 13:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 16:06 [PATCH v2] x86/mm: Fix use of uninitialized buffer in sme_enable() Nikita Zhandarovich
2023-03-13 12:49 ` Tom Lendacky
2023-03-16 13:45 ` [tip: x86/urgent] " tip-bot2 for Nikita Zhandarovich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®