# \[PATCH\] nfc: fix potential NULL pointer deref in nfc\_genl\_dump\_ses\_done

- Subsystems: NETWORKING \[GENERAL\], NFC SUBSYSTEM, THE REST
- Maintainers: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Willem de Bruijn, David Heidelberg, Linus Torvalds
- Status: LANDED (4cd8371a234d · 2021-12-09 15:50)
- Landed in mainline as 4cd8371a234d on 2021-12-09.
- List: netdev
- 2 messages, 2 authors
- Page: https://ratatoskr.run/netdev/2021/12/1602148/t

## \[PATCH\] nfc: fix potential NULL pointer deref in nfc\_genl\_dump\_ses\_done

- From: Krzysztof Kozlowski \<hidden\>
- Date: 2021-12-09 08:13:13 
- Message: https://ratatoskr.run/netdev/2021/12/1602148.md

```text
The done() netlink callback nfc_genl_dump_ses_done() should check if
received argument is non-NULL, because its allocation could fail earlier
in dumpit() (nfc_genl_dump_ses()).

Fixes: ac22ac466a65 ("NFC: Add a GET_SE netlink API")
Cc: <redacted>
Signed-off-by: Krzysztof Kozlowski <redacted>
---
 net/nfc/netlink.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 334f63c9529e..5c706ed75b33 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -1392,8 +1392,10 @@ static int nfc_genl_dump_ses_done(struct netlink_callback *cb)
 {
 	struct class_dev_iter *iter = (struct class_dev_iter *) cb->args[0];
 
-	nfc_device_iter_exit(iter);
-	kfree(iter);
+	if (iter) {
+		nfc_device_iter_exit(iter);
+		kfree(iter);
+	}
 
 	return 0;
 }
-- 
2.32.0

```

## Re: \[PATCH\] nfc: fix potential NULL pointer deref in nfc\_genl\_dump\_ses\_done

- From: patchwork-bot+netdevbpf@kernel.org
- Date: 2021-12-09 16:00:20 
- Message: https://ratatoskr.run/netdev/2021/12/1602767.md

```text
Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski [ref]:

On Thu,  9 Dec 2021 09:13:07 +0100 you wrote:
> The done() netlink callback nfc_genl_dump_ses_done() should check if
> received argument is non-NULL, because its allocation could fail earlier
> in dumpit() (nfc_genl_dump_ses()).
> 
> Fixes: ac22ac466a65 ("NFC: Add a GET_SE netlink API")
> Cc: <redacted>
> Signed-off-by: Krzysztof Kozlowski <redacted>
> 
> [...]

Here is the summary with links:
  - nfc: fix potential NULL pointer deref in nfc_genl_dump_ses_done
    https://git.kernel.org/netdev/net/c/fd79a0cbf0b2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html


```
