diff mbox series

[v2,1/1] net: ipv4: fix return value check in esp_remove_trailer()

Message ID 20230725064031.4472-1-ruc_gongyuanjun@163.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v2,1/1] net: ipv4: fix return value check in esp_remove_trailer() | 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: 1342 this patch: 1342
netdev/cc_maintainers warning 4 maintainers not CCed: kuba@kernel.org edumazet@google.com davem@davemloft.net pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 1365 this patch: 1365
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: 1365 this patch: 1365
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yuanjun Gong July 25, 2023, 6:40 a.m. UTC
return an error number if an unexpected result is returned by
pskb_tirm() in esp_remove_trailer().

Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
---
 net/ipv4/esp4.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Alexander Duyck July 25, 2023, 5:44 p.m. UTC | #1
On Tue, 2023-07-25 at 14:40 +0800, Yuanjun Gong wrote:
> return an error number if an unexpected result is returned by
> pskb_tirm() in esp_remove_trailer().
> 
> Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
> ---
>  net/ipv4/esp4.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
> index ba06ed42e428..b435e3fe4dc6 100644
> --- a/net/ipv4/esp4.c
> +++ b/net/ipv4/esp4.c
> @@ -732,7 +732,9 @@ static inline int esp_remove_trailer(struct sk_buff *skb)
>  		skb->csum = csum_block_sub(skb->csum, csumdiff,
>  					   skb->len - trimlen);
>  	}
> -	pskb_trim(skb, skb->len - trimlen);
> +	ret = pskb_trim(skb, skb->len - trimlen);
> +	if (ret)
> +		goto out;
>  
>  	ret = nexthdr[1];
>  

In what case would you encounter this error? From what I can tell it
looks like there are checks in the callers, specifically the call to
pskb_may_pull() at the start of esp_input() that will go through and
automatically eliminate all the potential reasons for this to fail. So
I am not sure what the point is in adding exception handling for an
exception that is already handled.
Herbert Xu July 28, 2023, 10 a.m. UTC | #2
On Tue, Jul 25, 2023 at 10:44:50AM -0700, Alexander H Duyck wrote:
> On Tue, 2023-07-25 at 14:40 +0800, Yuanjun Gong wrote:
> > return an error number if an unexpected result is returned by
> > pskb_tirm() in esp_remove_trailer().
> > 
> > Signed-off-by: Yuanjun Gong <ruc_gongyuanjun@163.com>
> > ---
> >  net/ipv4/esp4.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
> > index ba06ed42e428..b435e3fe4dc6 100644
> > --- a/net/ipv4/esp4.c
> > +++ b/net/ipv4/esp4.c
> > @@ -732,7 +732,9 @@ static inline int esp_remove_trailer(struct sk_buff *skb)
> >  		skb->csum = csum_block_sub(skb->csum, csumdiff,
> >  					   skb->len - trimlen);
> >  	}
> > -	pskb_trim(skb, skb->len - trimlen);
> > +	ret = pskb_trim(skb, skb->len - trimlen);
> > +	if (ret)
> > +		goto out;
> >  
> >  	ret = nexthdr[1];
> >  
> 
> In what case would you encounter this error? From what I can tell it
> looks like there are checks in the callers, specifically the call to
> pskb_may_pull() at the start of esp_input() that will go through and
> automatically eliminate all the potential reasons for this to fail. So
> I am not sure what the point is in adding exception handling for an
> exception that is already handled.

Good point.  pskb_trim should never fail at this point because
we've already made the packet completely writeable.

Perhaps we could add a comment?

Thanks,
diff mbox series

Patch

diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index ba06ed42e428..b435e3fe4dc6 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -732,7 +732,9 @@  static inline int esp_remove_trailer(struct sk_buff *skb)
 		skb->csum = csum_block_sub(skb->csum, csumdiff,
 					   skb->len - trimlen);
 	}
-	pskb_trim(skb, skb->len - trimlen);
+	ret = pskb_trim(skb, skb->len - trimlen);
+	if (ret)
+		goto out;
 
 	ret = nexthdr[1];