Re: generic_file_llseek() broken?

Trond Myklebust (trond.myklebust@fys.uio.no)
15 Nov 2001 10:55:07 +0100


>>>>> " " == Andreas Dilger <adilger@turbolabs.com> writes:

> --- linux.orig/fs/read_write.c Tue Aug 14 12:09:09 2001
> +++ linux/fs/read_write.c Thu Nov 15 01:54:35 2001
> @@ -36,15 +36,24 @@
> case 1:
> offset += file->f_pos;
> }
> +
> + /* LFS 2.1.1.6: can't seek to a position that doesn't fit in
> off_t */
> + retval = -EOVERFLOW;
> + if ((!(file->f_flags & O_LARGEFILE) && offset > MAX_NON_LFS)
> ||
> + offset > file->f_dentry->d_inode->i_sb->s_maxbytes)
> + goto out;
> +
> retval = -EINVAL;
> - if (offset>=0 &&
> offset<=file->f_dentry->d_inode->i_sb->s_maxbytes) {
> - if (offset != file->f_pos) {
> - file->f_pos = offset;
> - file->f_reada = 0;
> - file->f_version = ++event;
> - }
> - retval = offset;
> + if (offset < 0)
> + goto out;
> +
> + if (offset != file->f_pos) {
> + file->f_pos = offset;
> + file->f_reada = 0;
> + file->f_version = ++event;
> }
> + retval = offset;
> +out:
> return retval;
> }

> @@ -64,6 +73,12 @@
> case 1:
> offset += file->f_pos;
> }
> +
> + /* LFS 2.1.1.6: can't seek to a position that doesn't fit in
> off_t */
> + retval = -EOVERFLOW;
> + if (!(file->f_flags & O_LARGEFILE) && offset > MAX_NON_LFS)
> + goto out;
> +
> retval = -EINVAL; if (offset >= 0) {
> if (offset != file->f_pos) {
> @@ -73,6 +88,7 @@
> } retval = offset;
> }
> +out:
> return retval;
> }

> @@ -103,8 +119,6 @@
> if (origin <= 2) {
> loff_t res = llseek(file, offset, origin);
> retval = res;
> - if (res != (loff_t)retval)
> - retval = -EOVERFLOW; /* LFS: should only happen on 32 bit
> platforms */
> } fput(file);
> bad:

This breaks NFS badly for which a directory seek position is *not* a
file offset, but is an unsigned cookie. Please ensure that the above
checks are only made on regular files.

Cheers,
Trond
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/