diff mbox series

net: ieee802154: fix a null pointer in nl802154_trigger_scan

Message ID 20230307073004.74224-1-dzm91@hust.edu.cn (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: ieee802154: fix a null pointer in nl802154_trigger_scan | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 20 this patch: 20
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 20 this patch: 20
netdev/checkpatch warning WARNING: Reported-by: should be immediately followed by Link: with a URL to the report
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dongliang Mu March 7, 2023, 7:30 a.m. UTC
There is a null pointer dereference if NL802154_ATTR_SCAN_TYPE is
not set by the user.

Fix this by adding a null pointer check.

Reported-and-tested-by: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com
Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>
---
 net/ieee802154/nl802154.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Denis Kirjanov March 7, 2023, 8:43 a.m. UTC | #1
On 3/7/23 10:30, Dongliang Mu wrote:
> There is a null pointer dereference if NL802154_ATTR_SCAN_TYPE is
> not set by the user.
> 
> Fix this by adding a null pointer check.
> 
> Reported-and-tested-by: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com
> Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>

Please add a Fixes: tag 

> ---
>  net/ieee802154/nl802154.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
> index 2215f576ee37..1cf00cffd63f 100644
> --- a/net/ieee802154/nl802154.c
> +++ b/net/ieee802154/nl802154.c
> @@ -1412,7 +1412,8 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
>  		return -EOPNOTSUPP;
>  	}
>  
> -	if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> +	if (!info->attrs[NL802154_ATTR_SCAN_TYPE] ||
> +	    !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
>  		NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
>  		return -EINVAL;
>  	}
Miquel Raynal March 7, 2023, 9:09 a.m. UTC | #2
Hello,

dkirjanov@suse.de wrote on Tue, 7 Mar 2023 11:43:46 +0300:

> On 3/7/23 10:30, Dongliang Mu wrote:
> > There is a null pointer dereference if NL802154_ATTR_SCAN_TYPE is
> > not set by the user.
> > 
> > Fix this by adding a null pointer check.

Thanks for the patch! This has been fixed already:
https://lore.kernel.org/linux-wpan/20230301154450.547716-1-miquel.raynal@bootlin.com/T/#u

> > Reported-and-tested-by: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com

Just for reference, this tag shall not be used:

	"Please do not use combined tags, e.g.
	``Reported-and-tested-by``"
	Documentation/process/maintainer-tip.rst

> > Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>  
> 
> Please add a Fixes: tag 
> 
> > ---
> >  net/ieee802154/nl802154.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
> > index 2215f576ee37..1cf00cffd63f 100644
> > --- a/net/ieee802154/nl802154.c
> > +++ b/net/ieee802154/nl802154.c
> > @@ -1412,7 +1412,8 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
> >  		return -EOPNOTSUPP;
> >  	}
> >  
> > -	if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> > +	if (!info->attrs[NL802154_ATTR_SCAN_TYPE] ||
> > +	    !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> >  		NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
> >  		return -EINVAL;
> >  	}  


Thanks,
Miquèl
Dongliang Mu March 7, 2023, 9:09 a.m. UTC | #3
> -----原始邮件-----
> 发件人: "Denis Kirjanov" <dkirjanov@suse.de>
> 发送时间: 2023-03-07 16:43:46 (星期二)
> 收件人: "Dongliang Mu" <dzm91@hust.edu.cn>, "Alexander Aring" <alex.aring@gmail.com>, "Stefan Schmidt" <stefan@datenfreihafen.org>, "Miquel Raynal" <miquel.raynal@bootlin.com>, "David S. Miller" <davem@davemloft.net>, "Eric Dumazet" <edumazet@google.com>, "Jakub Kicinski" <kuba@kernel.org>, "Paolo Abeni" <pabeni@redhat.com>
> 抄送: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com, linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
> 主题: Re: [PATCH] net: ieee802154: fix a null pointer in nl802154_trigger_scan
> 
> 
> 
> On 3/7/23 10:30, Dongliang Mu wrote:
> > There is a null pointer dereference if NL802154_ATTR_SCAN_TYPE is
> > not set by the user.
> > 
> > Fix this by adding a null pointer check.
> > 
> > Reported-and-tested-by: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com
> > Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>
> 
> Please add a Fixes: tag 

I've sent a v2 patch. Thanks for your reminder.

> 
> > ---
> >  net/ieee802154/nl802154.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
> > index 2215f576ee37..1cf00cffd63f 100644
> > --- a/net/ieee802154/nl802154.c
> > +++ b/net/ieee802154/nl802154.c
> > @@ -1412,7 +1412,8 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
> >  		return -EOPNOTSUPP;
> >  	}
> >  
> > -	if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> > +	if (!info->attrs[NL802154_ATTR_SCAN_TYPE] ||
> > +	    !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> >  		NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
> >  		return -EINVAL;
> >  	}
Dongliang Mu March 7, 2023, 9:21 a.m. UTC | #4
> -----原始邮件-----
> 发件人: "Miquel Raynal" <miquel.raynal@bootlin.com>
> 发送时间: 2023-03-07 17:09:03 (星期二)
> 收件人: "Denis Kirjanov" <dkirjanov@suse.de>
> 抄送: "Dongliang Mu" <dzm91@hust.edu.cn>, "Alexander Aring" <alex.aring@gmail.com>, "Stefan Schmidt" <stefan@datenfreihafen.org>, "David
>  S. Miller" <davem@davemloft.net>, "Eric Dumazet" <edumazet@google.com>, "Jakub
>  Kicinski" <kuba@kernel.org>, "Paolo Abeni" <pabeni@redhat.com>, syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com, linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
> 主题: Re: [PATCH] net: ieee802154: fix a null pointer in nl802154_trigger_scan
> 
> Hello,
> 
> dkirjanov@suse.de wrote on Tue, 7 Mar 2023 11:43:46 +0300:
> 
> > On 3/7/23 10:30, Dongliang Mu wrote:
> > > There is a null pointer dereference if NL802154_ATTR_SCAN_TYPE is
> > > not set by the user.
> > > 
> > > Fix this by adding a null pointer check.
> 
> Thanks for the patch! This has been fixed already:
> https://lore.kernel.org/linux-wpan/20230301154450.547716-1-miquel.raynal@bootlin.com/T/#u

Oh, I see. Thanks for your reply.

A small issue: should we still check !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])?

> 
> > > Reported-and-tested-by: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com
> 
> Just for reference, this tag shall not be used:
> 
> 	"Please do not use combined tags, e.g.
> 	``Reported-and-tested-by``"
> 	Documentation/process/maintainer-tip.rst
> 

Okay. This is suggested by Syzbot. I will use separate tags in the future.

> > > Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>  
> > 
> > Please add a Fixes: tag 
> > 
> > > ---
> > >  net/ieee802154/nl802154.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
> > > index 2215f576ee37..1cf00cffd63f 100644
> > > --- a/net/ieee802154/nl802154.c
> > > +++ b/net/ieee802154/nl802154.c
> > > @@ -1412,7 +1412,8 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
> > >  		return -EOPNOTSUPP;
> > >  	}
> > >  
> > > -	if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> > > +	if (!info->attrs[NL802154_ATTR_SCAN_TYPE] ||
> > > +	    !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> > >  		NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
> > >  		return -EINVAL;
> > >  	}  
> 
> 
> Thanks,
> Miquèl


--
Best regards,
Dongliang Mu
Miquel Raynal March 7, 2023, 9:34 a.m. UTC | #5
Hi 慕冬亮,

dzm91@hust.edu.cn wrote on Tue, 7 Mar 2023 17:21:49 +0800 (GMT+08:00):

> > -----原始邮件-----
> > 发件人: "Miquel Raynal" <miquel.raynal@bootlin.com>
> > 发送时间: 2023-03-07 17:09:03 (星期二)
> > 收件人: "Denis Kirjanov" <dkirjanov@suse.de>
> > 抄送: "Dongliang Mu" <dzm91@hust.edu.cn>, "Alexander Aring" <alex.aring@gmail.com>, "Stefan Schmidt" <stefan@datenfreihafen.org>, "David
> >  S. Miller" <davem@davemloft.net>, "Eric Dumazet" <edumazet@google.com>, "Jakub
> >  Kicinski" <kuba@kernel.org>, "Paolo Abeni" <pabeni@redhat.com>, syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com, linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
> > 主题: Re: [PATCH] net: ieee802154: fix a null pointer in nl802154_trigger_scan
> > 
> > Hello,
> > 
> > dkirjanov@suse.de wrote on Tue, 7 Mar 2023 11:43:46 +0300:
> >   
> > > On 3/7/23 10:30, Dongliang Mu wrote:  
> > > > There is a null pointer dereference if NL802154_ATTR_SCAN_TYPE is
> > > > not set by the user.
> > > > 
> > > > Fix this by adding a null pointer check.  
> > 
> > Thanks for the patch! This has been fixed already:
> > https://lore.kernel.org/linux-wpan/20230301154450.547716-1-miquel.raynal@bootlin.com/T/#u  
> 
> Oh, I see. Thanks for your reply.
> 
> A small issue: should we still check !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])?

Isn't it already handled? There is a switch case over it with a default
statement to handle unsupported scan types.

> > > > Reported-and-tested-by: syzbot+bd85b31816913a32e473@syzkaller.appspotmail.com  
> > 
> > Just for reference, this tag shall not be used:
> > 
> > 	"Please do not use combined tags, e.g.
> > 	``Reported-and-tested-by``"
> > 	Documentation/process/maintainer-tip.rst
> >   
> 
> Okay. This is suggested by Syzbot. I will use separate tags in the future.
> 
> > > > Signed-off-by: Dongliang Mu <dzm91@hust.edu.cn>    
> > > 
> > > Please add a Fixes: tag 
> > >   
> > > > ---
> > > >  net/ieee802154/nl802154.c | 3 ++-
> > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
> > > > index 2215f576ee37..1cf00cffd63f 100644
> > > > --- a/net/ieee802154/nl802154.c
> > > > +++ b/net/ieee802154/nl802154.c
> > > > @@ -1412,7 +1412,8 @@ static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
> > > >  		return -EOPNOTSUPP;
> > > >  	}
> > > >  
> > > > -	if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> > > > +	if (!info->attrs[NL802154_ATTR_SCAN_TYPE] ||
> > > > +	    !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
> > > >  		NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
> > > >  		return -EINVAL;
> > > >  	}    
> > 
> > 
> > Thanks,
> > Miquèl  
> 
> 
> --
> Best regards,
> Dongliang Mu


Thanks,
Miquèl
diff mbox series

Patch

diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 2215f576ee37..1cf00cffd63f 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -1412,7 +1412,8 @@  static int nl802154_trigger_scan(struct sk_buff *skb, struct genl_info *info)
 		return -EOPNOTSUPP;
 	}
 
-	if (!nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
+	if (!info->attrs[NL802154_ATTR_SCAN_TYPE] ||
+	    !nla_get_u8(info->attrs[NL802154_ATTR_SCAN_TYPE])) {
 		NL_SET_ERR_MSG(info->extack, "Malformed request, missing scan type");
 		return -EINVAL;
 	}