public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: luka.gejak@linux.dev
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] staging: rtl8723bs: fix null pointer deref in rtw_check_bcn_info
Date: Wed, 15 Apr 2026 11:38:23 +0300	[thread overview]
Message-ID: <ad9Of-loRWcTmN3_@stanley.mountain> (raw)
In-Reply-To: <20260414205520.157861-1-luka.gejak@linux.dev>

On Tue, Apr 14, 2026 at 10:55:20PM +0200, luka.gejak@linux.dev wrote:
> From: Luka Gejak <luka.gejak@linux.dev>
> 
> When parsing beacon or probe response frames, if the ap does not provide
> a valid ssid ie, rtw_get_ie() returns NULL. The code then blindly
> performs a memcpy() using the returned NULL pointer (p + 2), resulting
> in a kernel oops or kernel panic due to a NULL pointer dereference.
> 
> Fix this by moving the memcpy() inside the if (p) block so it is only
> executed when a valid ssid ie is actually found.
> 
> Fixes: 370730894bec ("Staging: rtl8723bs: rtw_wlan_util: Add size check of SSID IE")
> Cc: stable@vger.kernel.org
> Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
> ---
>  drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
> index 6a7c09db4cd9..2a8aec37d9b0 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_wlan_util.c
> @@ -1204,8 +1204,8 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
>  		ssid_len = *(p + 1);
>  		if (ssid_len > NDIS_802_11_LENGTH_SSID)
>  			ssid_len = 0;
> +		memcpy(bssid->ssid.ssid, (p + 2), ssid_len);
>  	}
> -	memcpy(bssid->ssid.ssid, (p + 2), ssid_len);

This isn't a bug.  Doing an memcpy() of zero bytes is a no-op.

I think there might be an issue in user space where some of these
functions functions are marked as not accepting NULL pointers.  It leads
to weirdness because the compiler starts making assumptions based on
that and, for example, strips away all the subsequent NULL checks.  But
in the kernel it's fine.

Still this change does make the code more readable.  Please, could you
send the patch again with a commit message that explains that it is
not a bugfix, only a cleanup and remove the Fixes tag.

regards,
dan carpenter


      reply	other threads:[~2026-04-15  8:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-14 20:55 [PATCH] staging: rtl8723bs: fix null pointer deref in rtw_check_bcn_info luka.gejak
2026-04-15  8:38 ` Dan Carpenter [this message]

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=ad9Of-loRWcTmN3_@stanley.mountain \
    --to=error27@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=luka.gejak@linux.dev \
    --cc=stable@vger.kernel.org \
    /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