public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nfc: netlink: avoid NULL pointer dereference on error
@ 2015-10-07  9:33 Vincent Stehlé
  2015-10-20  4:50 ` Samuel Ortiz
  0 siblings, 1 reply; 2+ messages in thread
From: Vincent Stehlé @ 2015-10-07  9:33 UTC (permalink / raw)
  To: linux-wireless
  Cc: netdev, linux-kernel, Vincent Stehlé, Thierry Escande,
	Samuel Ortiz

The function nfc_genl_llc_sdreq() can dereference the dev pointer while
it is NULL on its error path. Create a new error handling label to avoid
that.

This fixes the following coccinelle error:

  ./net/nfc/netlink.c:1175:21-24: ERROR: dev is NULL but dereferenced.

Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
Cc: Thierry Escande <thierry.escande@linux.intel.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>
---
 net/nfc/netlink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 853172c..51c48f0 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1111,7 +1111,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
 	dev = nfc_get_device(idx);
 	if (!dev) {
 		rc = -ENODEV;
-		goto exit;
+		goto exit_nodev;
 	}
 
 	device_lock(&dev->dev);
@@ -1176,6 +1176,7 @@ exit:
 
 	nfc_put_device(dev);
 
+exit_nodev:
 	return rc;
 }
 
-- 
2.5.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] nfc: netlink: avoid NULL pointer dereference on error
  2015-10-07  9:33 [PATCH] nfc: netlink: avoid NULL pointer dereference on error Vincent Stehlé
@ 2015-10-20  4:50 ` Samuel Ortiz
  0 siblings, 0 replies; 2+ messages in thread
From: Samuel Ortiz @ 2015-10-20  4:50 UTC (permalink / raw)
  To: Vincent Stehlé; +Cc: linux-wireless, netdev, linux-kernel, Thierry Escande

Hi Vincent,

On Wed, Oct 07, 2015 at 11:33:19AM +0200, Vincent Stehlé wrote:
> The function nfc_genl_llc_sdreq() can dereference the dev pointer while
> it is NULL on its error path. Create a new error handling label to avoid
> that.
> 
> This fixes the following coccinelle error:
> 
>   ./net/nfc/netlink.c:1175:21-24: ERROR: dev is NULL but dereferenced.
> 
> Signed-off-by: Vincent Stehlé <vincent.stehle@laposte.net>
> Cc: Thierry Escande <thierry.escande@linux.intel.com>
> Cc: Samuel Ortiz <sameo@linux.intel.com>
> ---
>  net/nfc/netlink.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
> index 853172c..51c48f0 100644
> --- a/net/nfc/netlink.c
> +++ b/net/nfc/netlink.c
> @@ -1111,7 +1111,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)
>  	dev = nfc_get_device(idx);
>  	if (!dev) {
>  		rc = -ENODEV;
> -		goto exit;
> +		goto exit_nodev;
>  	}
Julia Lawall sent a better fix that I applied:

-       if (!dev) {
-               rc = -ENODEV;
-               goto exit;
-       }
+       if (!dev)
+               return -ENODEV;

Cheers,
Samuel.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-20  4:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-07  9:33 [PATCH] nfc: netlink: avoid NULL pointer dereference on error Vincent Stehlé
2015-10-20  4:50 ` Samuel Ortiz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox