netfilter: nfnetlink_queue: Fix redundant comparison of unsigned value
Subsystems (3)
PATCH 1/1 netfilter: nfnetlink_queue: Fix redundant comparison of unsigned value
The comparison seclen >= 0 in net/netfilter/nfnetlink_queue.c is redundant because seclen is an unsigned value, and such comparisons are always true.
This patch removes the unnecessary comparison replacing it with just 'greater than'
Discovered in coverity, CID 1602243
--- net/netfilter/nfnetlink_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_queue.c +3 -3
@@ -643,7 +643,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { seclen =nfqnl_get_sk_secctx (entskb, &ctx); -if (seclen >=0 ) +if (seclen >0 ) size +=nla_total_size (seclen); }
@@ -810,7 +810,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return skb;
@@ -819,7 +819,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return NULL ; }
Signature · 1 line
2.34.1
Pablo Neira Ayuso
maintainerHi,
Quoted 16 lines · Karol Przybylski
The comparison seclen >= 0 in
net/netfilter/nfnetlink_queue.cis redundant because seclen is an unsigned value, and such comparisons are always true.This patch removes the unnecessary comparison replacing it with just 'greater than'
Discovered in coverity, CID 1602243
Signed-off-by Karol Przybylski <[email protected]>--- net/netfilter/nfnetlink_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/netfilter/nfnetlink_queue.c +0
-0
net/netfilter/nfnetlink_queue.c nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, · line 646
Quoted 5 lines
net/netfilter/nfnetlink_queue.c +1
-1@@ -643,7 +643,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { seclen =nfqnl_get_sk_secctx (entskb, &ctx); -if (seclen >=0 ) +if (seclen >0 )
What tree are you using? I don't see this code in net-next.git
Quoted 24 lines
net/netfilter/nfnetlink_queue.c +2
-2size +=nla_total_size (seclen); }@@ -810,7 +810,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return skb;@@ -819,7 +819,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return NULL ; }Signature · 1 line
2.34.1
Quoted 21 lines · Pablo Neira Ayuso
Hi,
Quoted 17 lines · Karol Przybylski
The comparison seclen >= 0 in
net/netfilter/nfnetlink_queue.cis redundant because seclen is an unsigned value, and such comparisons are always true.This patch removes the unnecessary comparison replacing it with just 'greater than'
Discovered in coverity, CID 1602243
Signed-off-by Karol Przybylski <[email protected]>--- net/netfilter/nfnetlink_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/netfilter/nfnetlink_queue.c +0
-0@@ -643,7 +643,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
Quoted 6 lines
net/netfilter/nfnetlink_queue.c nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, · line 646
Quoted 4 lines
net/netfilter/nfnetlink_queue.c +1
-1if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { seclen =nfqnl_get_sk_secctx (entskb, &ctx); -if (seclen >=0 ) +if (seclen >0 )What tree are you using? I don't see this code in net-next.git
linux-next, next-20241209
Quoted 25 lines
Quoted 25 lines
net/netfilter/nfnetlink_queue.c +2
-3size +=nla_total_size (seclen); }@@ -810,7 +810,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return skb;@@ -819,7 +819,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return NULL ; } --2.34.1
Pablo Neira Ayuso
maintainerQuoted 29 lines · Karol P
Quoted 21 lines · Pablo Neira Ayuso
Hi,
Quoted 17 lines · Karol Przybylski
The comparison seclen >= 0 in
net/netfilter/nfnetlink_queue.cis redundant because seclen is an unsigned value, and such comparisons are always true.This patch removes the unnecessary comparison replacing it with just 'greater than'
Discovered in coverity, CID 1602243
Signed-off-by Karol Przybylski <[email protected]>--- net/netfilter/nfnetlink_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/netfilter/nfnetlink_queue.c +0
-0@@ -643,7 +643,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,Quoted 6 lines
net/netfilter/nfnetlink_queue.c nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, · line 646
Quoted 4 lines
net/netfilter/nfnetlink_queue.c +1
-1if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { seclen =nfqnl_get_sk_secctx (entskb, &ctx); -if (seclen >=0 ) +if (seclen >0 )What tree are you using? I don't see this code in net-next.git
Quoted 2 lines
linux-next, next-20241209
Could you trace from what commit ID and what tree this is coming?
Then, post the patch to the corresponding tree and add a Fixes: tag?
Possibly use:
if (seclen)
as this code was before?
Thanks.
Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
net/netfilter/nfnetlink_queue.c +2
-3size +=nla_total_size (seclen); }@@ -810,7 +810,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, } nlh->nlmsg_len = skb->len; -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return skb;@@ -819,7 +819,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,kfree_skb (skb);net_err_ratelimited ("nf_queue: error creating packet message\n" ); nlmsg_failure: -if (seclen >=0 ) +if (seclen >0 )security_release_secctx (&ctx);return NULL ; } --2.34.1
Florian Westphal
maintainerKarol Przybylski <[email protected]> wrote:
[ CC original patch author and mass-trimming CCs ]
Quoted 16 lines
The comparison seclen >= 0 in
net/netfilter/nfnetlink_queue.cis redundant because seclen is an unsigned value, and such comparisons are always true.This patch removes the unnecessary comparison replacing it with just 'greater than'
Discovered in coverity, CID 1602243
Signed-off-by Karol Przybylski <[email protected]>--- net/netfilter/nfnetlink_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/netfilter/nfnetlink_queue.c +0
-0
net/netfilter/nfnetlink_queue.c nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, · line 647
Quoted 6 lines
net/netfilter/nfnetlink_queue.c +1
-1@@ -643,7 +643,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { seclen =nfqnl_get_sk_secctx (entskb, &ctx); -if (seclen >=0 ) +if (seclen >0 ) size +=nla_total_size (seclen);
Casey, can you please have a look?
AFAICS security_secid_to_secctx() could return -EFOO, so it seems nfqnl_get_sk_secctx has a bug and should conceal < 0 retvals (the function returns u32), in addition to the always-true >= check fixup.
Quoted 21 lines · Florian Westphal
Karol Przybylski <[email protected]> wrote:
[ CC original patch author and mass-trimming CCs ]
Quoted 17 lines
The comparison seclen >= 0 in
net/netfilter/nfnetlink_queue.cis redundant because seclen is an unsigned value, and such comparisons are always true.This patch removes the unnecessary comparison replacing it with just 'greater than'
Discovered in coverity, CID 1602243
Signed-off-by Karol Przybylski <[email protected]>--- net/netfilter/nfnetlink_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)net/netfilter/nfnetlink_queue.c +0
-0@@ -643,7 +643,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue,
Quoted 6 lines
net/netfilter/nfnetlink_queue.c nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, · line 647
Quoted 5 lines
net/netfilter/nfnetlink_queue.c +1
-1if ((queue->flags &NFQA_CFG_F_SECCTX ) && entskb->sk) { seclen =nfqnl_get_sk_secctx (entskb, &ctx); -if (seclen >=0 ) +if (seclen >0 ) size +=nla_total_size (seclen);Casey, can you please have a look?
Yes, there is indeed an issue here. I will look into the correct change today. Thank you.
Quoted 5 lines
AFAICS
security_secid_to_secctx()could return-EFOO, so it seemsnfqnl_get_sk_secctxhas a bug and should conceal < 0 retvals (the function returns u32), in addition to the always-true >= check fixup.