From: Naotaka Hamaguchi <n.hamaguchi@jp.fujitsu.com>
To: Venu Byravarasu <vbyravarasu@nvidia.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Subject: Re: [PATCH] mm: mmap() sometimes succeeds even if the region to map is invalid.
Date: Mon, 20 Feb 2012 16:23:56 +0900 [thread overview]
Message-ID: <4F41F50C.1010508@jp.fujitsu.com> (raw)
In-Reply-To: <D958900912E20642BCBC71664EFECE3E6DD198A7AE@BGMAIL02.nvidia.com>
Hi Venu,
>> 1. mmap() succeeds even if "offset" argument is a negative value, although
>> it should return EINVAL in such case.
>
>> In such case, it is actually regarded as big positive value
>> because the type of "off" is "unsigned long" in the kernel.
>> For example, off=-4096 (-0x1000) is regarded as
>> off = 0xfffffffffffff000 (x86_64) and as off = 0xfffff000 (x86).
>> It results in mapping too big offset region.
>
> It is not true always.
>
> Considering your example, say if page size is 4k, then PAGE_MASK = 0xFFF
> hence (off& ~PAGE_MASK) will be true and " -EINVAL" will be returned.
Is PAGE_MASK 0xfffffffffffff000 (x86_64) and 0xfffff000 (x86), isn't it?
Or am I missing something?
arch/x86/include/asm/page_types.h
=================================================
...
#define PAGE_SHIFT 12
#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))
...
=================================================
Thanks,
Naotaka Hamaguchi
(2012/02/17 18:04), Venu Byravarasu wrote:
>> The detail of these problems is as follows:
>
>> 1. mmap() succeeds even if "offset" argument is a negative value, although
>> it should return EINVAL in such case.
>
>> In such case, it is actually regarded as big positive value
>> because the type of "off" is "unsigned long" in the kernel.
>> For example, off=-4096 (-0x1000) is regarded as
>> off = 0xfffffffffffff000 (x86_64) and as off = 0xfffff000 (x86).
>> It results in mapping too big offset region.
>
> It is not true always.
>
> Considering your example, say if page size is 4k, then PAGE_MASK = 0xFFF
> hence (off& ~PAGE_MASK) will be true and " -EINVAL" will be returned.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-02-20 7:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-17 8:43 Naotaka Hamaguchi
2012-02-17 9:04 ` Venu Byravarasu
2012-02-20 7:23 ` Naotaka Hamaguchi [this message]
2012-02-18 2:00 ` Hugh Dickins
2012-02-21 8:30 ` Naotaka Hamaguchi
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=4F41F50C.1010508@jp.fujitsu.com \
--to=n.hamaguchi@jp.fujitsu.com \
--cc=kosaki.motohiro@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vbyravarasu@nvidia.com \
/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