All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Kenzior <denkenz@gmail.com>
To: iwd@lists.01.org
Subject: Re: [PATCH] monitor: Add message length check to nlmon_receice
Date: Wed, 22 Jan 2020 11:53:47 -0600	[thread overview]
Message-ID: <448ecb92-848c-a2b2-8aad-ebe4a1b1772e@gmail.com> (raw)
In-Reply-To: <20200122172621.kol6ix6dqyswefe2@beryllium.lan>

[-- Attachment #1: Type: text/plain, Size: 1553 bytes --]

Hi Daniel,

>> NLMSG_OK and NLMSG_NEXT are macros in linux/netlink.h.  The problem is that
>> NLMSG_OK and NLMSG_NEXT expect to operate on an int according to 'man
>> netlink', but they don't actually cast the argument to an int.
>>
>> So what happens is that nlmsg_len underflows, wraps around to some large
>> number and the crash happens.
> 
> It's not the current message which triggers the crash, it's the next
> loop iteration which triggers the crash.

Right.  So after the last valid message, NLMSG_NEXT gets called which 
causes the underflow.  But since the type is unsigned, nlmsg_len just 
becomes a large number.  Then NLMSG_OK is invoked and thinks nlmsg_len 
is still all okay.

>>
>> Then I don't see how a crash would happen, wouldn't nlmsg_len just become 0
>> then?
> 
> The check would just abort the loop as soon a the lenght check
> triggers. I've tested the new version and nlmsg_len still got
> underflow but the macro aborts the loop now.

Right, that's the intent of NLMSG_OK and why it uses ints.

I still think the last message isn't *actually* aligned, but without 
crash data I can't prove it :)  It may be that most messages are indeed 
aligned, but the ones you're seeing this on are somehow special. 
Otherwise I don't see how we haven't detected this crash for so long.

> 
> Do you want me to send a new patch or are you going to fix it
> yourself? I don't mind :)

I went ahead and pushed 8b489d5df283 ("monitor: Fix crash") with your 
name on the Reported-By.

Regards,
-Denis

  reply	other threads:[~2020-01-22 17:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-19 16:31 [PATCH] monitor: Add message length check to nlmon_receice Daniel Wagner
2020-01-21 22:36 ` Denis Kenzior
2020-01-22  9:05   ` Daniel Wagner
2020-01-22 16:21     ` Denis Kenzior
2020-01-22 17:26       ` Daniel Wagner
2020-01-22 17:53         ` Denis Kenzior [this message]
2020-01-22 18:41           ` Daniel Wagner

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=448ecb92-848c-a2b2-8aad-ebe4a1b1772e@gmail.com \
    --to=denkenz@gmail.com \
    --cc=iwd@lists.01.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 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.