9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Venkatesh Srinivas <me@acm.jhu.edu>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: [9fans] segattach off-by-one?
Date: Thu, 24 Sep 2009 23:33:52 -0400	[thread overview]
Message-ID: <f75780240909242033k11fb23a0o237f7dbedf9a7bee@mail.gmail.com> (raw)

Hi,

This little program:

#include <u.h>
#include <libc.h>
#define SEGBASE ((char *) 0x10001001)
#define SEGSIZE 0x1000

void main(void) {
   segattach(0, "shared", SEGBASE, SEGSIZE);
   // Works fine (writing to 0x10001fff)
   *(char *) (SEGBASE + SEGSIZE - 2) = 'a';
   // Suicide! (writing to 0x10002000)
   *(char *) (SEGBASE + SEGSIZE - 1) = 'a';
}

However, segattach's manpage claims: "... and va+len is rounded up."
Shouldn't the second page here be mapped?

I propose this patch to /sys/src/9/port/segment.c::
--- segment.c.orig	2009-09-24 22:41:59.000000000 -0400
+++ segment.c	2009-09-24 22:38:25.000000000 -0400
@@ -641,6 +641,11 @@
 	int sno;
 	Segment *s, *os;
 	Physseg *ps;
+	ulong ova;
+
+	ova = va;
+	va = va&~(BY2PG-1);
+	len += (ova - va);

 	if(va != 0 && va >= USTKTOP)
 		error(Ebadarg);

This patch also prevents segattaching to the zero page, which I think
was worth doing...

Could people try this? Comments?

Thanks,
-- vs



             reply	other threads:[~2009-09-25  3:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-25  3:33 Venkatesh Srinivas [this message]
     [not found] <<f75780240909242033k11fb23a0o237f7dbedf9a7bee@mail.gmail.com>
2009-09-25  4:34 ` erik quanstrom
2009-09-25 18:01   ` Venkatesh Srinivas
2009-09-25 18:18     ` erik quanstrom
2009-09-25 18:32       ` erik quanstrom

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=f75780240909242033k11fb23a0o237f7dbedf9a7bee@mail.gmail.com \
    --to=me@acm.jhu.edu \
    --cc=9fans@9fans.net \
    /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).