mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Baruch Siach <baruch@tkos.co.il>
To: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] fs: add basic sanity check before accessing the files array
Date: Tue, 27 Jul 2010 16:52:08 +0300	[thread overview]
Message-ID: <20100727135208.GB13372@jasper.tkos.co.il> (raw)
In-Reply-To: <20100727133407.GH10913@game.jcrosoft.org>

Hi Jean-Christophe,

On Tue, Jul 27, 2010 at 03:34:07PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 	it will be better to use a common function to do the check

OK. Will do.

baruch

> On 16:16 Tue 27 Jul     , Baruch Siach wrote:
> > This patch adds some basic file descriptor sanity checks to the file access
> > routines. Check whether the given file descriptor is in the files array range,
> > and whether the file entry is valid.
> > 
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> >  fs/fs.c |   40 ++++++++++++++++++++++++++++++++++++++++
> >  1 files changed, 40 insertions(+), 0 deletions(-)
> > 
> > diff --git a/fs/fs.c b/fs/fs.c
> > index 8417067..449dcc2 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -457,6 +457,11 @@ int ioctl(int fd, int request, void *buf)
> >  	struct fs_driver_d *fsdrv;
> >  	FILE *f = &files[fd];
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return errno;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > @@ -474,6 +479,11 @@ int read(int fd, void *buf, size_t count)
> >  	struct fs_driver_d *fsdrv;
> >  	FILE *f = &files[fd];
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return errno;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > @@ -494,6 +504,11 @@ ssize_t write(int fd, const void *buf, size_t count)
> >  	struct fs_driver_d *fsdrv;
> >  	FILE *f = &files[fd];
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return errno;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > @@ -524,6 +539,11 @@ off_t lseek(int fildes, off_t offset, int whence)
> >  	FILE *f = &files[fildes];
> >  	off_t pos;
> >  
> > +	if (fildes < 0 || fildes >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return -1;
> > +	}
> > +
> >  	errno = 0;
> >  
> >  	dev = f->dev;
> > @@ -567,6 +587,11 @@ int erase(int fd, size_t count, unsigned long offset)
> >  	struct fs_driver_d *fsdrv;
> >  	FILE *f = &files[fd];
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return errno;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > @@ -589,6 +614,11 @@ int protect(int fd, size_t count, unsigned long offset, int prot)
> >  	struct fs_driver_d *fsdrv;
> >  	FILE *f = &files[fd];
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return errno;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > @@ -627,6 +657,11 @@ void *memmap(int fd, int flags)
> >  	FILE *f = &files[fd];
> >  	void *ret = (void *)-1;
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return ret;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > @@ -646,6 +681,11 @@ int close(int fd)
> >  	struct fs_driver_d *fsdrv;
> >  	FILE *f = &files[fd];
> >  
> > +	if (fd < 0 || fd >= MAX_FILES || !f->in_use) {
> > +		errno = -EBADF;
> > +		return errno;
> > +	}
> > +
> >  	dev = f->dev;
> >  
> >  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> > -- 
> > 1.7.1

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2010-07-27 13:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-27 13:16 Baruch Siach
2010-07-27 13:34 ` Jean-Christophe PLAGNIOL-VILLARD
2010-07-27 13:52   ` Baruch Siach [this message]
2010-07-28  5:27   ` [PATCHv2] " Baruch Siach
2010-07-28  6:22     ` Sascha Hauer

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=20100727135208.GB13372@jasper.tkos.co.il \
    --to=baruch@tkos.co.il \
    --cc=barebox@lists.infradead.org \
    --cc=plagnioj@jcrosoft.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