net: ipv4: Move ip_options_fragment() out of loop
Subsystems (3)
Hello Yajun Deng,
This is a semi-automatic email about new static checker warnings.
The patch faf482ca196a: "net: ipv4: Move ip_options_fragment() out of loop" from Aug 23, 2021, leads to the following Smatch complaint:
net/ipv4/ip_output.c:833 ip_do_fragment()
warn: variable dereferenced before check 'iter.frag' (see line 828)
net/ipv4/ip_output.c
827 ip_fraglist_init(skb, iph, hlen, &iter);
^^^^^iter.frag is set here.
828 ip_options_fragment(iter.frag);
^^^^^^^^^The patch introduces a new dereference here
829
830 for (;;) {
831 /* Prepare header of the next frame,
832 * before previous one went down. */
833 if (iter.frag) {
^^^^^^^^^But the old code assumed that "iter.frag" could be NULL.
834 IPCB(iter.frag)->flags = IPCB(skb)->flags; 835 ip_fraglist_prepare(skb, &iter);
regards,
dan carpenter
Quoted 3 lines · Dan Carpenter
Hello Yajun Deng,
This is a semi-automatic email about new static checker warnings.
Can you test the attached?
Thanks.
Quoted 24 lines
The patch
faf482ca196a: "net: ipv4: Moveip_options_fragment()out of loop" from Aug 23, 2021, leads to the following Smatch complaint:
net/ipv4/ip_output.c:833ip_do_fragment()
warn: variable dereferenced before check 'iter.frag' (see line 828)
net/ipv4/ip_output.c
827ip_fraglist_init(skb, iph, hlen, &iter); ^^^^^
iter.frag is set here.828
ip_options_fragment(iter.frag); ^^^^^^^^^
The patch introduces a new dereference here829
830 for (;;) {
831 /* Prepare header of the next frame,
832 * before previous one went down. */
833 if (iter.frag) {
^^^^^^^^^
But the old code assumed that "iter.frag" could be NULL.
Quoted 5 lines
834 IPCB(iter.frag)->flags = IPCB(skb)->flags; 835
ip_fraglist_prepare(skb, &iter);regards,
dan carpenter
From 19fda71966403608c3b2dc981b238a1c25865b83 Mon Sep 17 00:00:00 2001
From: Yajun Deng <[email protected]>
Date: Fri, 27 Aug 2021 17:14:43 +0800
Subject: [PATCH net-next] net: ipv4: Fix the warning for dereference
Dan Carpenter report:
The patch faf482ca196a: "net: ipv4: Move ip_options_fragment() out of loop" from Aug 23, 2021, leads to the following Smatch complaint:
net/ipv4/ip_output.c:833 ip_do_fragment()
warn: variable dereferenced before check 'iter.frag' (see line 828)
Add a if statements to avoid the warning.
--- net/ipv4/ip_output.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv4/ip_output.c +3 -1
@@ -825,7 +825,9 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,/* Everything is OK. Generate! */ ip_fraglist_init (skb, iph, hlen, &iter); -ip_options_fragment (iter.frag); + +if (iter.frag) +ip_options_fragment (iter.frag);for (;;) {/* Prepare header of the next frame,
Signature · 1 line
2.32.0
Quoted 8 lines · On Fri, Aug 27, 2021 at 09:23:22AM +0000, [email protected] wrote:
Quoted 3 lines · Dan Carpenter
Hello Yajun Deng,
This is a semi-automatic email about new static checker warnings.
Can you test the attached?
Looks good. Thanks!
regards,
dan carpenter