From: Daniel Borkmann <dborkman@redhat.com>
To: chetan loke <loke.chetan@gmail.com>
Cc: David Miller <davem@davemloft.net>,
netdev <netdev@vger.kernel.org>,
Jakub Zawadzki <darkjames-ws@darkjames.pl>
Subject: Re: [PATCH net] packet: tpacket_v3: do not trigger bug() on wrong header status
Date: Tue, 07 May 2013 22:49:35 +0200 [thread overview]
Message-ID: <518968DF.9070008@redhat.com> (raw)
In-Reply-To: <CAAsGZS7TVr2YX8H8EQRqk4gDwNMQiaOkjhwCuLM_27RqB6+QgQ@mail.gmail.com>
On 05/07/2013 06:59 PM, chetan loke wrote:
> On Fri, May 3, 2013 at 8:57 AM, Daniel Borkmann <dborkman@redhat.com> wrote:
>>
>> Jakub reported that it is fairly easy to trigger the BUG() macro
>> from user space with TPACKET_V3's RX_RING by just giving a wrong
>> header status flag. We already had a similar situation in commit
>> 7f5c3e3a80e6654 (``af_packet: remove BUG statement in
>> tpacket_destruct_skb'') where this was the case in the TX_RING
>> side that could be triggered from user space. So really, don't use
>> BUG() or BUG_ON() unless there's really no way out, and i.e.
>> don't use it for consistency checking when there's user space
>> involved, no excuses, especially not if you're slapping the user
>> with WARN + dump_stack + BUG all at once. The two functions are
>
> remember, you were able to figure out what the problem was because of
> the WARN and the forceful BUG.
> Is BUG ok? Depends on how you look at it. If you are doing serious
> network monitoring on a real life appliance
> we don't really want folks to write crappy application. May be BUG is
Right, and now we treat people who write crappy applications with BUG?
BUG is only for consistency checks *within* the kernel and not meant to
be triggered on purpose from user space.
> too harsh. But then I don't see a WARN in this patch either (may be I
> overlooked it).
So what's the point? If people see a WARN() in their kernel log they go
and complain on netdev that AF_PACKET is broken although its their
application?
There was already a discussion on netdev with a different BUG macro in
the TX_RING, where we concluded that it shouldn't be a warn either.
>> of concern:
>>
>> prb_retire_current_block() [when block status != TP_STATUS_KERNEL]
>> prb_open_block() [when block_status != TP_STATUS_KERN
>
>>
>> Calls to prb_open_block() are guarded by ealier checks if block_status
>> is really TP_STATUS_KERNEL (racy!), but the first one BUG() is easily
>> triggable from user space. System behaves still stable after they are
>> removed. Also remove that yoda condition entirely, since it's already
>> guarded.
>
> What yoda? It's called defensive programming. It's a single check and
> not going to cost you anything.
Yoda condition is called if you compare ``CONSTANT == var'', actually the
other way round as it should be in CodingStyle. But that's not the big issue
here, as Jakub pointed out it's racy because you do this comparison two
times and status could change in between, thus you trigger the next BUG
there, like (pseudo code):
if (frame_status & USERPSACE) {
...
} else {
if (frame_status & KERNEL) {
...
} else {
BUG
}
}
next prev parent reply other threads:[~2013-05-07 20:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-03 12:57 [PATCH net] packet: tpacket_v3: do not trigger bug() on wrong header status Daniel Borkmann
2013-05-03 20:12 ` David Miller
2013-05-07 16:59 ` chetan loke
2013-05-07 20:49 ` Daniel Borkmann [this message]
2013-05-07 21:56 ` Eric Dumazet
2013-05-07 21:58 ` David Miller
2013-05-08 20:32 ` chetan loke
2013-05-09 0:51 ` Daniel Borkmann
2013-05-09 18:11 ` chetan loke
2013-05-09 18:32 ` Daniel Borkmann
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=518968DF.9070008@redhat.com \
--to=dborkman@redhat.com \
--cc=darkjames-ws@darkjames.pl \
--cc=davem@davemloft.net \
--cc=loke.chetan@gmail.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).