Skip to content

Commit

Permalink
powerpc/spufs: Check file offset before calculating write size in fix…
Browse files Browse the repository at this point in the history
…ed-sized files

Based on an original patch from Roel Kluin <roel.kluin@gmail.com>.

The write size calculated during regs and fpcr writes may currently
go negative. Because size is unsigned, this will wrap, and our
check for EFBIG will fail.

Instead, do the check for EFBIG before subtracting from size.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
  • Loading branch information
Jeremy Kerr authored and Benjamin Herrenschmidt committed Mar 11, 2009
1 parent e7eec2f commit d219889
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions arch/powerpc/platforms/cell/spufs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,10 @@ spufs_regs_write(struct file *file, const char __user *buffer,
struct spu_lscsa *lscsa = ctx->csa.lscsa;
int ret;

size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
if (size <= 0)
if (*pos >= sizeof(lscsa->gprs))
return -EFBIG;

size = min_t(ssize_t, sizeof(lscsa->gprs) - *pos, size);
*pos += size;

ret = spu_acquire_saved(ctx);
Expand Down Expand Up @@ -623,10 +624,11 @@ spufs_fpcr_write(struct file *file, const char __user * buffer,
struct spu_lscsa *lscsa = ctx->csa.lscsa;
int ret;

size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
if (size <= 0)
if (*pos >= sizeof(lscsa->fpcr))
return -EFBIG;

size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);

ret = spu_acquire_saved(ctx);
if (ret)
return ret;
Expand Down

0 comments on commit d219889

Please sign in to comment.