public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Jan Stancek <jstancek@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] mmapstress04: rewrite to fix heap overwrite
Date: Wed, 3 May 2017 08:49:46 -0400 (EDT)	[thread overview]
Message-ID: <1681486633.6527722.1493815786828.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <20170503123541.GA794@rei.suse.de>



----- Original Message -----
> Hi!
> > +static void setup(void)
> > +{
> > +	page_size = getpagesize();
> > +
> > +	/*
> > +	 * Pick large enough area, PROT_NONE doesn't matter,
> > +	 * because we remap it later.
> > +	 */
> > +	mmap_area = SAFE_MMAP(NULL, page_size * NUM_PAGES, PROT_NONE,
> > +		MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
> > +}
> > +
> > +static void write_fully(int fd, void *buf, int len)
> > +{
> > +	do {
> > +		len -= SAFE_WRITE(0, fd, buf, len);
> > +		buf += len;
> 
> This appears to be wrong. If SAFE_WRITE() writes 1 byte we end up with
> offset len - 1 and lenght len - 1 which will cause reads outside of the
> buffer.

You're right, it's wrong :-(.

> 
> We have to do:
> 
> 		ret = SAFE_WRITE(...);
> 		buf += ret;
> 		len -= ret;
> 
> > +	} while (len > 0);
> > +}
> 
> Otherwise it's fine. Acked with the write function fixed.

Fixed and pushed.

Regards,
Jan

      reply	other threads:[~2017-05-03 12:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-03  9:00 [LTP] [PATCH v2] mmapstress04: rewrite to fix heap overwrite Jan Stancek
2017-05-03 12:35 ` Cyril Hrubis
2017-05-03 12:49   ` Jan Stancek [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=1681486633.6527722.1493815786828.JavaMail.zimbra@redhat.com \
    --to=jstancek@redhat.com \
    --cc=ltp@lists.linux.it \
    /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