From: Andrey Ryabinin <ryabinin.a.a@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Xishi Qiu <qiuxishi@huawei.com>,
Andrey Konovalov <adech.fo@gmail.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Michal Marek <mmarek@suse.cz>,
"long.wanglong" <long.wanglong@huawei.com>,
Linux MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kasan: use IS_ALIGNED in memory_is_poisoned_8()
Date: Mon, 14 Sep 2015 16:19:24 +0300 [thread overview]
Message-ID: <CAPAsAGxq8pKuGpmZ9T-JB_3MP+QcTgsUpFOv-0u2a+tqfkej9w@mail.gmail.com> (raw)
In-Reply-To: <20150911154730.3a2151a0b111fed01acdaaa1@linux-foundation.org>
2015-09-12 1:47 GMT+03:00 Andrew Morton <akpm@linux-foundation.org>:
> On Fri, 11 Sep 2015 10:02:29 +0800 Xishi Qiu <qiuxishi@huawei.com> wrote:
>> - if (likely(((addr + 7) & KASAN_SHADOW_MASK) >= 7))
>> + if (likely(IS_ALIGNED(addr, 8)))
>> return false;
>
> Wouldn't IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE) be more appropriate?
>
> But I'm not really sure what the original code is trying to do.
>
Original code is trying to estimate whether we should check 2 shadow
bytes or just 1 should be enough.
> if ((addr + 7) & 7) >= 7)
>
> can only evaluate true if ((addr + 7) & 7) equals 7, so the ">=" could
> be "==".
>
Yes, it could be "==".
">=" is just for consistency with similar code in memory_is_poisoned_2/4.
If I'm not mistaken generic formula for such check looks like this:
((addr + size - 1) & KASAN_SHADOW_MASK) >= ((size - 1) &
KASAN_SHADOW_MASK)
But when size >= KASAN_SHADOW_SCALE_SIZE we could just check for alignment.
> I think. The code looks a bit weird. A code comment would help.
>
> And how come memory_is_poisoned_16() does IS_ALIGNED(addr, 8)? Should
> it be 16?
>
No, If 16 bytes are 8-byte aligned, then shadow is 2-bytes.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2015-09-14 13:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-11 2:02 Xishi Qiu
2015-09-11 22:47 ` Andrew Morton
2015-09-14 1:17 ` Xishi Qiu
2015-09-14 13:19 ` Andrey Ryabinin [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=CAPAsAGxq8pKuGpmZ9T-JB_3MP+QcTgsUpFOv-0u2a+tqfkej9w@mail.gmail.com \
--to=ryabinin.a.a@gmail.com \
--cc=adech.fo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=long.wanglong@huawei.com \
--cc=mmarek@suse.cz \
--cc=qiuxishi@huawei.com \
--cc=rusty@rustcorp.com.au \
/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