linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: Wenli Looi <wlooi@ucalgary.ca>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: rtl8723bs: Fix uninitialized variable
Date: Sun, 06 Jun 2021 10:45:58 +0200	[thread overview]
Message-ID: <7256195.zb9d8qvCYo@linux.local> (raw)
In-Reply-To: <CAKe_nd0fNE=+CP4O0cUtOPO5vRC8_gHxjLtH80r_4GO2MW5u4g@mail.gmail.com>

On Sunday, June 6, 2021 10:09:39 AM CEST Wenli Looi wrote:
> On Sun, Jun 6, 2021 at 1:00 AM Fabio M. De Francesco
> 
> <fmdefrancesco@gmail.com> wrote:
> > On Sunday, June 6, 2021 9:51:35 AM CEST Wenli Looi wrote:
> > > On Sun, Jun 6, 2021 at 12:13 AM Greg Kroah-Hartman
> > > 
> > > <gregkh@linuxfoundation.org> wrote:
> > > > On Sun, Jun 06, 2021 at 12:00:21AM -0700, Wenli Looi wrote:
> > > > > Uninitialized struct with invalid pointer causes BUG and prevents 
access
> > > > > point from working. Access point works once I apply this patch.
> > > > > 
> > > > > https://forum.armbian.com/topic/14727-wifi-ap-kernel-bug-in-kernel-5444/
> > > > > has more details.
> > > > > 
> > > > > Signed-off-by: Wenli Looi <wlooi@ucalgary.ca>
> > > > > ---
> > > > > 
> > > > >  drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> > > > > b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c index 
2fb80b6eb..
> > 
> > 7308e1185
> > 
> > > > > 100644
> > > > > --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> > > > > +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> > > > > @@ -2384,7 +2384,7 @@ void rtw_cfg80211_indicate_sta_assoc(struct
> > 
> > adapter *padapter,
> > 
> > > > > u8 *pmgmt_frame,> >
> > > > > 
> > > > >       DBG_871X(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
> > > > >       
> > > > >       {
> > > > > 
> > > > > -             struct station_info sinfo;
> > > > > +             struct station_info sinfo = {};
> > > > 
> > > > What caused this bug to show up?  Did it happen from some other 
commit?
> > > > 
> > > > Are you sure that all of the fields are being cleared properly here,
> > > > what about any "holes" in the structure?
> > > > 
> > > > thanks,
> > > > greg k-h
[CUT]
> > > 
> > > Do you think kzalloc() would be preferable?
> > 
> > You cannot use kzalloc there: 'sinfo' is instantiated automatically on the
> > stack. The example you took had a pointer to the struct.
> 
> The stack variable could be replaced with code like:
> 
> struct station_info *sinfo;if (!sinfo)
>
Why that "if (!sinfo" before kzalloc?
>
> sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
> ...
> cfg80211_new_sta(..., sinfo, ...);
> kfree(sinfo);
> 
> which is what the linked code basically does. I'm not sure if this is 
preferred?
>
I don't know that code, but I think that:

(1) It is generally preferred that big structures should be allocated 
dinamically: kernel stack is a scarce resource.
(2) Passing address of variables from the stack to other functions is 
generally a good source of troubles.

I think you are closer to the proper solution.

Fabio 
>
> > 
> > > Sorry, I'm not familiar with "holes" in the struct.





  reply	other threads:[~2021-06-06  8:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-06  7:00 [PATCH] staging: rtl8723bs: Fix uninitialized variable Wenli Looi
2021-06-06  7:13 ` Greg Kroah-Hartman
2021-06-06  7:51   ` Wenli Looi
2021-06-06  8:00     ` Fabio M. De Francesco
2021-06-06  8:09       ` Wenli Looi
2021-06-06  8:45         ` Fabio M. De Francesco [this message]
2021-06-06 18:46           ` [PATCH v2] " Wenli Looi
2021-06-07  8:35             ` Dan Carpenter
2021-06-07  8:46               ` Dan Carpenter
2021-06-08  6:35                 ` Wenli Looi
2021-06-07  8:33 ` [PATCH] " Dan Carpenter
2021-06-07  9:23   ` Greg Kroah-Hartman
2021-06-07 10:43     ` Dan Carpenter
2021-06-08  6:46   ` [PATCH] staging: rtl8723bs: Fix uninitialized variables Wenli Looi
2021-06-08  7:20     ` Dan Carpenter

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=7256195.zb9d8qvCYo@linux.local \
    --to=fmdefrancesco@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=wlooi@ucalgary.ca \
    /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;
as well as URLs for NNTP newsgroup(s).