diff mbox series

[net] gtp: allow -1 to be specified as file description from userspace

Message ID 20241022144825.66740-1-pablo@netfilter.org (mailing list archive)
State Accepted
Commit 7515e37bce5c428a56a9b04ea7e96b3f53f17150
Delegated to: Netdev Maintainers
Headers show
Series [net] gtp: allow -1 to be specified as file description from userspace | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers fail 2 blamed authors not CCed: cong.wang@bytedance.com horms@kernel.org; 3 maintainers not CCed: andrew+netdev@lunn.ch cong.wang@bytedance.com horms@kernel.org
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch warning WARNING: line length of 82 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-23--12-00 (tests: 777)

Commit Message

Pablo Neira Ayuso Oct. 22, 2024, 2:48 p.m. UTC
Existing user space applications maintained by the Osmocom project are
breaking since a recent fix that addresses incorrect error checking.

Restore operation for user space programs that specify -1 as file
descriptor to skip GTPv0 or GTPv1 only sockets.

Fixes: defd8b3c37b0 ("gtp: fix a potential NULL pointer dereference")
Reported-by: Pau Espin Pedrol <pespin@sysmocom.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 drivers/net/gtp.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

Comments

Oliver Smith Oct. 23, 2024, 9:26 a.m. UTC | #1
Hello Pablo,

I've reproduced the regression:

> 20241023090545167 DGGSN NOTICE Initialized GTP kernel mode (genl ID is 32) (gtp-kernel.c:80)
> [    0.721705] gtp: enable gtp on -1, 4
> [    0.722017] gtp: gtp socket fd=-1 not found
> 20241023090545169 DTUN ERROR cannot create GTP tunnel device: Bad file descriptor (tun.c:213)

and verified that it is fixed with your patch. Thanks!

Best regards,
Oliver

On 22.10.24 16:48, Pablo Neira Ayuso wrote:
> Existing user space applications maintained by the Osmocom project are
> breaking since a recent fix that addresses incorrect error checking.
> 
> Restore operation for user space programs that specify -1 as file
> descriptor to skip GTPv0 or GTPv1 only sockets.
> 
> Fixes: defd8b3c37b0 ("gtp: fix a potential NULL pointer dereference")
> Reported-by: Pau Espin Pedrol <pespin@sysmocom.de>

Tested-by: Oliver Smith <osmith@sysmocom.de>

> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
>   drivers/net/gtp.c | 22 +++++++++++++---------
>   1 file changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
> index a60bfb1abb7f..70f981887518 100644
> --- a/drivers/net/gtp.c
> +++ b/drivers/net/gtp.c
> @@ -1702,20 +1702,24 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
>   		return -EINVAL;
>   
>   	if (data[IFLA_GTP_FD0]) {
> -		u32 fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
> +		int fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
>   
> -		sk0 = gtp_encap_enable_socket(fd0, UDP_ENCAP_GTP0, gtp);
> -		if (IS_ERR(sk0))
> -			return PTR_ERR(sk0);
> +		if (fd0 >= 0) {
> +			sk0 = gtp_encap_enable_socket(fd0, UDP_ENCAP_GTP0, gtp);
> +			if (IS_ERR(sk0))
> +				return PTR_ERR(sk0);
> +		}
>   	}
>   
>   	if (data[IFLA_GTP_FD1]) {
> -		u32 fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
> +		int fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
>   
> -		sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
> -		if (IS_ERR(sk1u)) {
> -			gtp_encap_disable_sock(sk0);
> -			return PTR_ERR(sk1u);
> +		if (fd1 >= 0) {
> +			sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
> +			if (IS_ERR(sk1u)) {
> +				gtp_encap_disable_sock(sk0);
> +				return PTR_ERR(sk1u);
> +			}
>   		}
>   	}
>
Simon Horman Oct. 24, 2024, 12:30 p.m. UTC | #2
+ Cong and Andrew

On Tue, Oct 22, 2024 at 04:48:25PM +0200, Pablo Neira Ayuso wrote:
> Existing user space applications maintained by the Osmocom project are
> breaking since a recent fix that addresses incorrect error checking.
> 
> Restore operation for user space programs that specify -1 as file
> descriptor to skip GTPv0 or GTPv1 only sockets.
> 
> Fixes: defd8b3c37b0 ("gtp: fix a potential NULL pointer dereference")
> Reported-by: Pau Espin Pedrol <pespin@sysmocom.de>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

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

> ---
>  drivers/net/gtp.c | 22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
> index a60bfb1abb7f..70f981887518 100644
> --- a/drivers/net/gtp.c
> +++ b/drivers/net/gtp.c
> @@ -1702,20 +1702,24 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
>  		return -EINVAL;
>  
>  	if (data[IFLA_GTP_FD0]) {
> -		u32 fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
> +		int fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
>  
> -		sk0 = gtp_encap_enable_socket(fd0, UDP_ENCAP_GTP0, gtp);
> -		if (IS_ERR(sk0))
> -			return PTR_ERR(sk0);
> +		if (fd0 >= 0) {
> +			sk0 = gtp_encap_enable_socket(fd0, UDP_ENCAP_GTP0, gtp);
> +			if (IS_ERR(sk0))
> +				return PTR_ERR(sk0);
> +		}
>  	}
>  
>  	if (data[IFLA_GTP_FD1]) {
> -		u32 fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
> +		int fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
>  
> -		sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
> -		if (IS_ERR(sk1u)) {
> -			gtp_encap_disable_sock(sk0);
> -			return PTR_ERR(sk1u);
> +		if (fd1 >= 0) {
> +			sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
> +			if (IS_ERR(sk1u)) {
> +				gtp_encap_disable_sock(sk0);
> +				return PTR_ERR(sk1u);
> +			}
>  		}
>  	}
>  
> -- 
> 2.30.2
> 
>
patchwork-bot+netdevbpf@kernel.org Oct. 29, 2024, 6:30 p.m. UTC | #3
Hello:

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

On Tue, 22 Oct 2024 16:48:25 +0200 you wrote:
> Existing user space applications maintained by the Osmocom project are
> breaking since a recent fix that addresses incorrect error checking.
> 
> Restore operation for user space programs that specify -1 as file
> descriptor to skip GTPv0 or GTPv1 only sockets.
> 
> Fixes: defd8b3c37b0 ("gtp: fix a potential NULL pointer dereference")
> Reported-by: Pau Espin Pedrol <pespin@sysmocom.de>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> [...]

Here is the summary with links:
  - [net] gtp: allow -1 to be specified as file description from userspace
    https://git.kernel.org/netdev/net/c/7515e37bce5c

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
index a60bfb1abb7f..70f981887518 100644
--- a/drivers/net/gtp.c
+++ b/drivers/net/gtp.c
@@ -1702,20 +1702,24 @@  static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
 		return -EINVAL;
 
 	if (data[IFLA_GTP_FD0]) {
-		u32 fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
+		int fd0 = nla_get_u32(data[IFLA_GTP_FD0]);
 
-		sk0 = gtp_encap_enable_socket(fd0, UDP_ENCAP_GTP0, gtp);
-		if (IS_ERR(sk0))
-			return PTR_ERR(sk0);
+		if (fd0 >= 0) {
+			sk0 = gtp_encap_enable_socket(fd0, UDP_ENCAP_GTP0, gtp);
+			if (IS_ERR(sk0))
+				return PTR_ERR(sk0);
+		}
 	}
 
 	if (data[IFLA_GTP_FD1]) {
-		u32 fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
+		int fd1 = nla_get_u32(data[IFLA_GTP_FD1]);
 
-		sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
-		if (IS_ERR(sk1u)) {
-			gtp_encap_disable_sock(sk0);
-			return PTR_ERR(sk1u);
+		if (fd1 >= 0) {
+			sk1u = gtp_encap_enable_socket(fd1, UDP_ENCAP_GTP1U, gtp);
+			if (IS_ERR(sk1u)) {
+				gtp_encap_disable_sock(sk0);
+				return PTR_ERR(sk1u);
+			}
 		}
 	}