netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] gtp: fix a potential NULL pointer dereference
@ 2024-08-25 19:16 Cong Wang
  2024-08-27 14:41 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Cong Wang @ 2024-08-25 19:16 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Andreas Schultz, Pablo Neira Ayuso, Harald Welte

From: Cong Wang <cong.wang@bytedance.com>

When sockfd_lookup() fails, gtp_encap_enable_socket() returns a
NULL pointer, but its callers only check for error pointers thus miss
the NULL pointer case.

Fix it by returning an error pointer with the error code carried from
sockfd_lookup().

(I found this bug during code inspection.)

Fixes: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional")
Cc: Andreas Schultz <aschultz@tpip.net>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Harald Welte <laforge@gnumonks.org>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 drivers/net/gtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index 0696faf60013..2e94d10348cc 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -1653,7 +1653,7 @@ static struct sock *gtp_encap_enable_socket(int fd, int type,
 	sock = sockfd_lookup(fd, &err);
 	if (!sock) {
 		pr_debug("gtp socket fd=%d not found\n", fd);
-		return NULL;
+		return ERR_PTR(err);
 	}
 
 	sk = sock->sk;
-- 
2.34.1


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

* Re: [Patch net] gtp: fix a potential NULL pointer dereference
  2024-08-25 19:16 [Patch net] gtp: fix a potential NULL pointer dereference Cong Wang
@ 2024-08-27 14:41 ` Simon Horman
  2024-08-27 16:05 ` Pablo Neira Ayuso
  2024-08-27 21:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2024-08-27 14:41 UTC (permalink / raw)
  To: Cong Wang
  Cc: netdev, Cong Wang, Andreas Schultz, Pablo Neira Ayuso,
	Harald Welte

On Sun, Aug 25, 2024 at 12:16:38PM -0700, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> When sockfd_lookup() fails, gtp_encap_enable_socket() returns a
> NULL pointer, but its callers only check for error pointers thus miss
> the NULL pointer case.
> 
> Fix it by returning an error pointer with the error code carried from
> sockfd_lookup().
> 
> (I found this bug during code inspection.)
> 
> Fixes: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional")
> Cc: Andreas Schultz <aschultz@tpip.net>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Cc: Harald Welte <laforge@gnumonks.org>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>

Thanks Cong,

I agree with your analysis.

Reviewed-by: Simon Horman <horms@kernel.org>

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

* Re: [Patch net] gtp: fix a potential NULL pointer dereference
  2024-08-25 19:16 [Patch net] gtp: fix a potential NULL pointer dereference Cong Wang
  2024-08-27 14:41 ` Simon Horman
@ 2024-08-27 16:05 ` Pablo Neira Ayuso
  2024-08-27 21:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2024-08-27 16:05 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, Cong Wang, Andreas Schultz, Harald Welte

On Sun, Aug 25, 2024 at 12:16:38PM -0700, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> When sockfd_lookup() fails, gtp_encap_enable_socket() returns a
> NULL pointer, but its callers only check for error pointers thus miss
> the NULL pointer case.
> 
> Fix it by returning an error pointer with the error code carried from
> sockfd_lookup().
> 
> (I found this bug during code inspection.)
> 
> Fixes: 1e3a3abd8b28 ("gtp: make GTP sockets in gtp_newlink optional")
> Cc: Andreas Schultz <aschultz@tpip.net>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Cc: Harald Welte <laforge@gnumonks.org>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>

Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>

Thanks.

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

* Re: [Patch net] gtp: fix a potential NULL pointer dereference
  2024-08-25 19:16 [Patch net] gtp: fix a potential NULL pointer dereference Cong Wang
  2024-08-27 14:41 ` Simon Horman
  2024-08-27 16:05 ` Pablo Neira Ayuso
@ 2024-08-27 21:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-27 21:30 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, cong.wang, aschultz, pablo, laforge

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 25 Aug 2024 12:16:38 -0700 you wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> When sockfd_lookup() fails, gtp_encap_enable_socket() returns a
> NULL pointer, but its callers only check for error pointers thus miss
> the NULL pointer case.
> 
> Fix it by returning an error pointer with the error code carried from
> sockfd_lookup().
> 
> [...]

Here is the summary with links:
  - [net] gtp: fix a potential NULL pointer dereference
    https://git.kernel.org/netdev/net/c/defd8b3c37b0

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



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

end of thread, other threads:[~2024-08-27 21:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-25 19:16 [Patch net] gtp: fix a potential NULL pointer dereference Cong Wang
2024-08-27 14:41 ` Simon Horman
2024-08-27 16:05 ` Pablo Neira Ayuso
2024-08-27 21:30 ` patchwork-bot+netdevbpf

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).