From: yajun.deng@linux.dev
To: "Dan Carpenter" <dan.carpenter@oracle.com>
Cc: netdev@vger.kernel.org
Subject: Re: [bug report] net: ipv4: Move ip_options_fragment() out of loop
Date: Fri, 27 Aug 2021 09:23:22 +0000 [thread overview]
Message-ID: <31823d969f554ffd04e5f9b3b459ecf4@linux.dev> (raw)
In-Reply-To: <20210827084915.GA8737@kili>
[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]
August 27, 2021 4:49 PM, "Dan Carpenter" <dan.carpenter@oracle.com> wrote:
> Hello Yajun Deng,
>
> This is a semi-automatic email about new static checker warnings.
Can you test the attached?
Thanks.
>
> 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
[-- Attachment #2: 0001-net-ipv4-Fix-the-warning-for-dereference.patch --]
[-- Type: application/octet-stream, Size: 1235 bytes --]
From 19fda71966403608c3b2dc981b238a1c25865b83 Mon Sep 17 00:00:00 2001
From: Yajun Deng <yajun.deng@linux.dev>
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.
Fixes: faf482ca196a ("net: ipv4: Move ip_options_fragment() out of loop")
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
net/ipv4/ip_output.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index 9a8f05d5476e..9bca57ef8b83 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -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,
--
2.32.0
next prev parent reply other threads:[~2021-08-27 9:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-27 8:49 [bug report] net: ipv4: Move ip_options_fragment() out of loop Dan Carpenter
2021-08-27 9:23 ` yajun.deng [this message]
2021-08-30 7:38 ` Dan Carpenter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31823d969f554ffd04e5f9b3b459ecf4@linux.dev \
--to=yajun.deng@linux.dev \
--cc=dan.carpenter@oracle.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).