All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
To: Jacob Siverskog <jacob@teenage.engineering>
Cc: David Miller <davem@davemloft.net>,
	Rainer Weikusat <rweikusat@mobileactivedefense.com>,
	netdev@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>,
	Eric Dumazet <edumazet@google.com>,
	Konstantin Khlebnikov <khlebnikov@yandex-team.ru>,
	Al Viro <viro@zeniv.linux.org.uk>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: Fix potential NULL pointer dereference in __skb_try_recv_datagram
Date: Wed, 30 Dec 2015 15:32:31 +0000	[thread overview]
Message-ID: <87fuykuf3k.fsf@doppelsaurus.mobileactivedefense.com> (raw)
In-Reply-To: <CAEnXRPtJBoOn+JgXDEUdL07WkbYVViAT_+LBiV4X=NVQ3SiDaQ@mail.gmail.com> (Jacob Siverskog's message of "Wed, 30 Dec 2015 12:14:42 +0100")

Jacob Siverskog <jacob@teenage.engineering> writes:
> On Tue, Dec 29, 2015 at 9:08 PM, David Miller <davem@davemloft.net> wrote:
>> From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
>> Date: Tue, 29 Dec 2015 19:42:36 +0000
>>
>>> Jacob Siverskog <jacob@teenage.engineering> writes:
>>>> This should fix a NULL pointer dereference I encountered (dump
>>>> below). Since __skb_unlink is called while walking,
>>>> skb_queue_walk_safe should be used.
>>>
>>> The code in question is:
>>  ...
>>> __skb_unlink is only called prior to returning from the function.
>>> Consequently, it won't affect the skb_queue_walk code.
>>
>> Agreed, this patch doesn't fix anything.
>
> Ok. Thanks for your feedback. How do you believe the issue could be
> solved? Investigating it gives:
>
> static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
> {

[...]

> next->prev = prev;
>      530: e5823004 str r3, [r2, #4]                          <--
> trapping instruction (r2 NULL)
>
> Register contents:
> r7 : c58cfe1c  r6 : c06351d0  r5 : c77810ac  r4 : c583eac0
> r3 : 00000000  r2 : 00000000  r1 : 00000000  r0 : 20000013
>
> If I understand this correctly, then r4 = skb, r2 = next, r3 = prev.

Some additional information which may be helpful: The next->prev = prev
was pretty obvious from the original error message alone: The invalid
access happened at 4 but no register contained 4. Considering that this
is for ARM, this must have been caused by an instruction using an
address of the form

[Rx, #4]

ie, value of register x + 4. And the next->prev = prev is the only
access to something located 4 bytes beyond something else.

> Should there be a check for this in __skb_try_recv_datagram?

These lists are supposed to be circular, ie, the next pointer of the
last element should point to the first and the prev pointer of the first
to the last. If there's an element with ->next == NULL on the list,
something either didn't do inserts correctly or corrupted an originally
intact list.

General advice: The original error occurred with 4.3.0. Had this
happened to me, I'd either tried to locate the error in the same kernel
version or to reproduce the bug with the one I was planning to
modify. Trying to fix a 'strange memory access' error which was observed
with version x.y by modifying version x.z is IMHO needlessly moving on
shaky ground.


      parent reply	other threads:[~2015-12-30 15:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-29 19:10 [PATCH] net: Fix potential NULL pointer dereference in __skb_try_recv_datagram Jacob Siverskog
2015-12-29 19:42 ` Rainer Weikusat
2015-12-29 20:08   ` David Miller
2015-12-30 11:14     ` Jacob Siverskog
2015-12-30 13:26       ` Eric Dumazet
2015-12-30 14:30         ` Jacob Siverskog
2015-12-30 14:38           ` Eric Dumazet
2015-12-30 22:30           ` Cong Wang
2016-01-04  9:10             ` Jacob Siverskog
2016-01-04 15:25               ` Eric Dumazet
2016-01-04 16:14                 ` Rainer Weikusat
2016-01-04 16:45                   ` Eric Dumazet
2016-01-05 11:07                 ` Jacob Siverskog
2016-01-05 14:14                   ` Eric Dumazet
2016-01-05 14:34                     ` Jacob Siverskog
2016-01-05 14:39                       ` Eric Dumazet
2016-01-20 15:06                         ` Jacob Siverskog
2016-01-20 15:48                           ` Eric Dumazet
2016-01-20 16:17                             ` Jacob Siverskog
2016-01-20 17:02                               ` Eric Dumazet
2016-01-20 16:38                       ` Peter Hurley
2015-12-30 15:32       ` Rainer Weikusat [this message]

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=87fuykuf3k.fsf@doppelsaurus.mobileactivedefense.com \
    --to=rweikusat@mobileactivedefense.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jacob@teenage.engineering \
    --cc=khlebnikov@yandex-team.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.