* [PATCH #2.6.27-rc5] mmap: fix petty bug in anonymous shared mmap offset handling
@ 2008-09-03 14:09 Tejun Heo
2008-09-03 16:25 ` Hugh Dickins
0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2008-09-03 14:09 UTC (permalink / raw)
To: linux-mm, Linux Kernel Mailing List, Linus Torvalds
Anonymous mappings should ignore offset but shared anonymous mapping
forgot to clear it and makes the following legit test program trigger
SIGBUS.
#include <sys/mman.h>
#include <stdio.h>
#include <errno.h>
#define PAGE_SIZE 4096
int main(void)
{
char *p;
int i;
p = mmap(NULL, 2 * PAGE_SIZE, PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_ANONYMOUS, -1, PAGE_SIZE);
if (p == MAP_FAILED) {
perror("mmap");
return 1;
}
for (i = 0; i < 2; i++) {
printf("page %d\n", i);
p[i * 4096] = i;
}
return 0;
}
Fix it.
Signed-off-by: Tejun Heo <tj@kernel.org>
---
mm/mmap.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/mmap.c b/mm/mmap.c
index 339cf5c..e7a5a68 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1030,6 +1030,10 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
} else {
switch (flags & MAP_TYPE) {
case MAP_SHARED:
+ /*
+ * Ignore pgoff.
+ */
+ pgoff = 0;
vm_flags |= VM_SHARED | VM_MAYSHARE;
break;
case MAP_PRIVATE:
--
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH #2.6.27-rc5] mmap: fix petty bug in anonymous shared mmap offset handling
2008-09-03 14:09 [PATCH #2.6.27-rc5] mmap: fix petty bug in anonymous shared mmap offset handling Tejun Heo
@ 2008-09-03 16:25 ` Hugh Dickins
2008-09-04 2:51 ` KOSAKI Motohiro
0 siblings, 1 reply; 3+ messages in thread
From: Hugh Dickins @ 2008-09-03 16:25 UTC (permalink / raw)
To: Tejun Heo
Cc: linux-mm, Linux Kernel Mailing List, Linus Torvalds, Andrew Morton
On Wed, 3 Sep 2008, Tejun Heo wrote:
> Anonymous mappings should ignore offset but shared anonymous mapping
> forgot to clear it and makes the following legit test program trigger
> SIGBUS.
>
> #include <sys/mman.h>
> #include <stdio.h>
> #include <errno.h>
>
> #define PAGE_SIZE 4096
>
> int main(void)
> {
> char *p;
> int i;
>
> p = mmap(NULL, 2 * PAGE_SIZE, PROT_READ|PROT_WRITE,
> MAP_SHARED|MAP_ANONYMOUS, -1, PAGE_SIZE);
> if (p == MAP_FAILED) {
> perror("mmap");
> return 1;
> }
>
> for (i = 0; i < 2; i++) {
> printf("page %d\n", i);
> p[i * 4096] = i;
> }
> return 0;
> }
>
> Fix it.
>
> Signed-off-by: Tejun Heo <tj@kernel.org>
Fair enough. The current behaviour has (almost) never bothered us,
so I'm uncertain if your test is legit, but I can't see any reason
to object to the change. Particularly since (just out of sight below
the context of your patch) we force pgoff in the MAP_PRIVATE case.
Acked-by: Hugh Dickins <hugh@veritas.com>
> ---
> mm/mmap.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 339cf5c..e7a5a68 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1030,6 +1030,10 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
> } else {
> switch (flags & MAP_TYPE) {
> case MAP_SHARED:
> + /*
> + * Ignore pgoff.
> + */
> + pgoff = 0;
> vm_flags |= VM_SHARED | VM_MAYSHARE;
> break;
> case MAP_PRIVATE:
--
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH #2.6.27-rc5] mmap: fix petty bug in anonymous shared mmap offset handling
2008-09-03 16:25 ` Hugh Dickins
@ 2008-09-04 2:51 ` KOSAKI Motohiro
0 siblings, 0 replies; 3+ messages in thread
From: KOSAKI Motohiro @ 2008-09-04 2:51 UTC (permalink / raw)
To: Hugh Dickins
Cc: kosaki.motohiro, Tejun Heo, linux-mm, Linux Kernel Mailing List,
Linus Torvalds, Andrew Morton
> > Signed-off-by: Tejun Heo <tj@kernel.org>
>
> Fair enough. The current behaviour has (almost) never bothered us,
> so I'm uncertain if your test is legit, but I can't see any reason
> to object to the change. Particularly since (just out of sight below
> the context of your patch) we force pgoff in the MAP_PRIVATE case.
>
> Acked-by: Hugh Dickins <hugh@veritas.com>
me too.
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
--
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-04 2:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-03 14:09 [PATCH #2.6.27-rc5] mmap: fix petty bug in anonymous shared mmap offset handling Tejun Heo
2008-09-03 16:25 ` Hugh Dickins
2008-09-04 2:51 ` KOSAKI Motohiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox