diff mbox series

net: xfrm: fix return value check in ipcomp_compress

Message ID 20231006114106.3982925-1-make_ruc2021@163.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: xfrm: fix return value check in ipcomp_compress | 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: 1362 this patch: 1362
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang fail Errors and warnings before: 17 this patch: 17
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 fail Errors and warnings before: 17 this patch: 17
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

Ma Ke Oct. 6, 2023, 11:41 a.m. UTC
In ipcomp_compress, to avoid an unexpected result returned by
pskb_trim, we should check the return value of pskb_trim().

Signed-off-by: Ma Ke <make_ruc2021@163.com>
---
 net/xfrm/xfrm_ipcomp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Florian Westphal Oct. 6, 2023, 11:47 a.m. UTC | #1
Ma Ke <make_ruc2021@163.com> wrote:
> In ipcomp_compress, to avoid an unexpected result returned by
> pskb_trim, we should check the return value of pskb_trim().
> 
> Signed-off-by: Ma Ke <make_ruc2021@163.com>
> ---
>  net/xfrm/xfrm_ipcomp.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
> index 9c0fa0e1786a..5f2e6edadf48 100644
> --- a/net/xfrm/xfrm_ipcomp.c
> +++ b/net/xfrm/xfrm_ipcomp.c
> @@ -144,7 +144,9 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
>  	memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
>  	local_bh_enable();
>  
> -	pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
> +	err = pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
> +	if (unlikely(err))
> +		goto out;

This can't be right, this now calls local_bh_enable() twice.
Florian Westphal Oct. 6, 2023, 11:59 a.m. UTC | #2
Florian Westphal <fw@strlen.de> wrote:
> Ma Ke <make_ruc2021@163.com> wrote:
> > In ipcomp_compress, to avoid an unexpected result returned by
> > pskb_trim, we should check the return value of pskb_trim().
> > 
> > Signed-off-by: Ma Ke <make_ruc2021@163.com>
> > ---
> >  net/xfrm/xfrm_ipcomp.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
> > index 9c0fa0e1786a..5f2e6edadf48 100644
> > --- a/net/xfrm/xfrm_ipcomp.c
> > +++ b/net/xfrm/xfrm_ipcomp.c
> > @@ -144,7 +144,9 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
> >  	memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
> >  	local_bh_enable();
> >  
> > -	pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
> > +	err = pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
> > +	if (unlikely(err))
> > +		goto out;
> 
> This can't be right, this now calls local_bh_enable() twice.

Furthermore, looking at this:

1. skb went through skb_linearize_cow() before, so no paged data anymore

2. Right before there is a check to bail in case compression inflated
packet size.

IOW, this pskb_trim cannot fail, it boils down to __skb_trim().
diff mbox series

Patch

diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c
index 9c0fa0e1786a..5f2e6edadf48 100644
--- a/net/xfrm/xfrm_ipcomp.c
+++ b/net/xfrm/xfrm_ipcomp.c
@@ -144,7 +144,9 @@  static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
 	memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
 	local_bh_enable();
 
-	pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
+	err = pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
+	if (unlikely(err))
+		goto out;
 	return 0;
 
 out: