linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Rodgman <dave.rodgman@arm.com>
To: Yueyi Li <liyueyi@live.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "dsterba@suse.cz" <dsterba@suse.cz>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"w@1wt.eu" <w@1wt.eu>,
	"donb@securitymouse.com" <donb@securitymouse.com>,
	"markus@oberhumer.com" <markus@oberhumer.com>, nd <nd@arm.com>
Subject: Re: [PATCH v2] lzo: fix ip overrun during compress.
Date: Fri, 30 Nov 2018 12:20:44 +0000	[thread overview]
Message-ID: <3bde9678-ac05-62f1-bfc3-434832adda11@arm.com> (raw)
In-Reply-To: <SN1PR13MB030426DBA527C725AE28B5A9DFD30@SN1PR13MB0304.namprd13.prod.outlook.com>

> On 2018/11/30 0:49, Dave Rodgman wrote:
>> On 28/11/2018 1:52 pm, David Sterba wrote:
>>
>>> The fix is adding a few branches to code that's supposed to be as fast
>>> as possible. The branches would be evaluated all the time while
>>> protecting against one signle bad page address. This does not look like
>>> a good performance tradeoff.
>> As an alternative, for all but the first case, instead of:
>>
>> if (unlikely(OVERFLOW_ADD_CHECK(ip, m_len) || (ip + m_len >= ip_end)))
>>
>> I'd suggest we do:
>>
>> if (unlikely((ip_end - ip) <= m_len))
>>
>> which will be about as efficient as what's currently there, but doesn't
>> have issues with overflow.
> 
> Ooh, yes, pretty good solution to this, thanks.

Np :-)

Actually, looking more closely at the first case, something like this 
works quite well:

size_t inc = 1 + ((ip - ii) >> 5);
if (unlikely((ip_end - ip) <= inc))
	break;
ip += inc;

On arm64, this generates only a single branch instruction, so it's only 
two extra arithmetic operations more than the original code (using the 
macro results in an additional compare & branch).

I used this to explore the compiler output:

https://godbolt.org/z/ng2qGZ

Dave

  reply	other threads:[~2018-11-30 12:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28  7:31 [PATCH v2] lzo: fix ip overrun during compress Yueyi Li
2018-11-28 13:52 ` David Sterba
2018-11-28 14:15   ` Willy Tarreau
2018-11-29 16:49   ` Dave Rodgman
2018-11-30  3:05     ` Yueyi Li
2018-11-30 12:20       ` Dave Rodgman [this message]
2018-12-03  2:46         ` Yueyi Li
2018-12-03  3:05           ` Yueyi Li
2018-12-04 10:20   ` Markus F.X.J. Oberhumer
2018-12-05  3:07     ` Yueyi Li
2018-12-06 15:03       ` Markus F.X.J. Oberhumer
2018-12-12  5:21         ` Yueyi Li
2018-12-12 12:35           ` Markus F.X.J. Oberhumer
2018-12-14 13:56             ` Richard Weinberger
2018-12-14 16:46               ` Kees Cook
2018-12-16 16:56                 ` Markus F.X.J. Oberhumer
2018-12-18  9:25                   ` Yueyi Li

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=3bde9678-ac05-62f1-bfc3-434832adda11@arm.com \
    --to=dave.rodgman@arm.com \
    --cc=donb@securitymouse.com \
    --cc=dsterba@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liyueyi@live.com \
    --cc=markus@oberhumer.com \
    --cc=nd@arm.com \
    --cc=w@1wt.eu \
    /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).