mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Andryuk <jason.andryuk@amd.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	Mario Limonciello <mario.limonciello@amd.com>,
	Thomas Gleixner <tglx@kernel.org>, <x86@kernel.org>,
	Yazen Ghannam <yazen.ghannam@amd.com>,
	<linux-kernel@vger.kernel.org>, Penny Zheng <penny.zheng@amd.com>,
	<stable@vger.kernel.org>,
	"Mario Limonciello (AMD)" <superm1@kernel.org>
Subject: Re: [PATCH v3 2/2] x86/amd_node: Remove smn_exclusive
Date: Tue, 1 Sep 2026 07:59:45 -0400	[thread overview]
Message-ID: <05dce607-fb34-4962-be0c-9316ee8f4be3@amd.com> (raw)
In-Reply-To: <20260901002705.GFapYb2c6fPJYqokRi@fat_crate.local>

On 2026-08-31 20:27, Borislav Petkov wrote:
> On Mon, Aug 31, 2026 at 01:52:08PM -0400, Jason Andryuk wrote:
>> No, the code and the comment are both correct as posted.  It's just that I
>> wrote the comment reversed from the code to state the positive property we
>> want.
> 
> So if amd_smn_init() succeeds, that means we have registered the PCI config
> regions of the PCI roots, including the SMN ones, as IORESOURCE_EXCLUSIVE and
> they won't be exported to userspace through /dev/mem and what not.
> 
> So, any caller of __amd_smn_rw() should fail because it is coming from kernel
> space and it can expect that userspace could interfere with the hw and thus
> not a good idea.
> 
> So yes, this is what got me confused and the (!amd_roots) check is correct.
> 
>> I'll change this whichever way you want.  It's not a big deal, which is why
>> I added the comment like you requested originally.
> 
> I think I already "intercepted" your suggestion, see here:
> 
>  From 1a1c4addc5a14e9ef2bb7d351a62ff4563d0f10a Mon Sep 17 00:00:00 2001
> From: Jason Andryuk <jason.andryuk@amd.com>
> Date: Tue, 25 Aug 2026 17:48:03 -0400
> Subject: [PATCH] x86/amd_node: Prevent potential NULL pointer dereference
> 
> amd_smn_read/write() are exported functions around __amd_smn_rw(), so
> they are always available even if amd_smn_init() fails. In that case,
> amd_roots is NULL and __amd_smn_rw() will access uninitialized memory.
> 
> Then, commit
> 
>    83518453074d ("x86/amd_node: Add SMN offsets to exclusive region access")
> 
> added smn_exclusive which indicated the calls to
> pci_request_config_region_exclusive() succeeded to prevent concurrent
> userspace access.
> 
> Commit
> 
>    0a4b61d9c2e4 ("x86/amd_node: Fix AMD root device caching")
> 
> re-ordered initialization so pci_request_config_region_exclusive() is called
> earlier and a failure exits amd_smn_init() before allocating amd_roots.
> Setting smn_exclusive moved to the end of amd_smn_init(), after amd_roots is
> allocated. It became redundant and can be removed.
> 
> Replace smn_exclusive with directly checking amd_roots to avoid a potential
> NULL pointer dereference.
> 
>    [ bp: Reorg commit message, touchup comment. ]
> 
> Fixes: 77466b798d59 ("x86/amd_node: Remove dependency on AMD_NB")
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
> Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com>
> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> Cc: stable@vger.kernel.org
> Link: https://patch.msgid.link/20260825214805.39148-3-jason.andryuk@amd.com
Looks good to me.

Thanks,
Jason

  reply	other threads:[~2026-09-01 11:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25 21:48 [PATCH v3 0/2] x86/amd_node: Fixes for virtualized systems Jason Andryuk
2026-08-25 21:48 ` [PATCH v3 1/2] x86/amd_node: Avoid divide by zero on " Jason Andryuk
2026-08-26  4:45   ` Borislav Petkov
2026-08-26 12:15     ` Jason Andryuk
2026-08-26 15:55       ` Borislav Petkov
2026-08-31 17:35   ` [tip: x86/urgent] " tip-bot2 for Jason Andryuk
2026-08-25 21:48 ` [PATCH v3 2/2] x86/amd_node: Remove smn_exclusive Jason Andryuk
2026-08-31  2:30   ` Borislav Petkov
2026-08-31 17:52     ` Jason Andryuk
2026-09-01  0:27       ` Borislav Petkov
2026-09-01 11:59         ` Jason Andryuk [this message]
2026-09-02 21:32   ` [tip: x86/urgent] x86/amd_node: Prevent potential NULL pointer dereference tip-bot2 for Jason Andryuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05dce607-fb34-4962-be0c-9316ee8f4be3@amd.com \
    --to=jason.andryuk@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mingo@redhat.com \
    --cc=penny.zheng@amd.com \
    --cc=stable@vger.kernel.org \
    --cc=superm1@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    --cc=yazen.ghannam@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®