All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] use symbolic constants in generic lseek code
@ 2007-02-20 21:57 Chris Snook
  2007-02-20 22:01 ` [PATCH 1/2] " Chris Snook
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chris Snook @ 2007-02-20 21:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, dhowells, jeffpc, csnook

The generic lseek code in fs/read_write.c uses hardcoded values for
SEEK_{SET,CUR,END}.

Patch 1 fixes the case statements to use the symbolic constants in
include/linux/fs.h, and should not be at all controversial.

Patch 2 adds a SEEK_MAX and uses it to validate user arguments.  This makes
the code a little cleaner and also enables future extensions (such as
SEEK_DATA and SEEK_HOLE).  If anyone has a problem with this, please speak up.

-- Chris


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] use symbolic constants in generic lseek code
  2007-02-20 21:57 [PATCH 0/2] use symbolic constants in generic lseek code Chris Snook
@ 2007-02-20 22:01 ` Chris Snook
  2007-02-20 22:05 ` [PATCH 2/2] use use SEEK_MAX to validate user lseek arguments Chris Snook
  2007-02-21 11:38 ` [PATCH 0/2] use symbolic constants in generic lseek code David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Snook @ 2007-02-20 22:01 UTC (permalink / raw)
  To: Chris Snook, linux-kernel; +Cc: akpm, dhowells, jeffpc, csnook

From: Chris Snook <csnook@redhat.com>

Convert magic numbers to SEEK_* values from fs.h

Signed-off-by: Chris Snook <csnook@redhat.com>
--
--- a/fs/read_write.c	2007-02-20 14:49:45.000000000 -0500
+++ b/fs/read_write.c	2007-02-20 16:48:39.000000000 -0500
@@ -37,10 +37,10 @@ loff_t generic_file_llseek(struct file *

 	mutex_lock(&inode->i_mutex);
 	switch (origin) {
-		case 2:
+		case SEEK_END:
 			offset += inode->i_size;
 			break;
-		case 1:
+		case SEEK_CUR:
 			offset += file->f_pos;
 	}
 	retval = -EINVAL;
@@ -63,10 +63,10 @@ loff_t remote_llseek(struct file *file,

 	lock_kernel();
 	switch (origin) {
-		case 2:
+		case SEEK_END:
 			offset += i_size_read(file->f_path.dentry->d_inode);
 			break;
-		case 1:
+		case SEEK_CUR:
 			offset += file->f_pos;
 	}
 	retval = -EINVAL;
@@ -94,10 +94,10 @@ loff_t default_llseek(struct file *file,

 	lock_kernel();
 	switch (origin) {
-		case 2:
+		case SEEK_END:
 			offset += i_size_read(file->f_path.dentry->d_inode);
 			break;
-		case 1:
+		case SEEK_CUR:
 			offset += file->f_pos;
 	}
 	retval = -EINVAL;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] use use SEEK_MAX to validate user lseek arguments
  2007-02-20 21:57 [PATCH 0/2] use symbolic constants in generic lseek code Chris Snook
  2007-02-20 22:01 ` [PATCH 1/2] " Chris Snook
@ 2007-02-20 22:05 ` Chris Snook
  2007-02-21 11:38 ` [PATCH 0/2] use symbolic constants in generic lseek code David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: Chris Snook @ 2007-02-20 22:05 UTC (permalink / raw)
  To: Chris Snook, linux-kernel; +Cc: akpm, dhowells, jeffpc, csnook

From: Chris Snook <csnook@redhat.com>

Add SEEK_MAX and use it to validate lseek arguments from userspace.

Signed-off-by: Chris Snook <csnook@redhat.com>
--
diff -urp b/fs/read_write.c c/fs/read_write.c
--- b/fs/read_write.c	2007-02-20 16:48:39.000000000 -0500
+++ c/fs/read_write.c	2007-02-20 16:55:46.000000000 -0500
@@ -139,7 +139,7 @@ asmlinkage off_t sys_lseek(unsigned int
 		goto bad;

 	retval = -EINVAL;
-	if (origin <= 2) {
+	if (origin <= SEEK_MAX) {
 		loff_t res = vfs_llseek(file, offset, origin);
 		retval = res;
 		if (res != (loff_t)retval)
@@ -166,7 +166,7 @@ asmlinkage long sys_llseek(unsigned int
 		goto bad;

 	retval = -EINVAL;
-	if (origin > 2)
+	if (origin > SEEK_MAX)
 		goto out_putf;

 	offset = vfs_llseek(file, ((loff_t) offset_high << 32) | offset_low,
diff -urp b/include/linux/fs.h c/include/linux/fs.h
--- b/include/linux/fs.h	2007-02-20 14:49:46.000000000 -0500
+++ c/include/linux/fs.h	2007-02-20 16:54:30.000000000 -0500
@@ -30,6 +30,7 @@
 #define SEEK_SET	0	/* seek relative to beginning of file */
 #define SEEK_CUR	1	/* seek relative to current file position */
 #define SEEK_END	2	/* seek relative to end of file */
+#define SEEK_MAX	SEEK_END

 /* And dynamically-tunable limits and defaults: */
 struct files_stat_struct {


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] use symbolic constants in generic lseek code
  2007-02-20 21:57 [PATCH 0/2] use symbolic constants in generic lseek code Chris Snook
  2007-02-20 22:01 ` [PATCH 1/2] " Chris Snook
  2007-02-20 22:05 ` [PATCH 2/2] use use SEEK_MAX to validate user lseek arguments Chris Snook
@ 2007-02-21 11:38 ` David Howells
  2 siblings, 0 replies; 4+ messages in thread
From: David Howells @ 2007-02-21 11:38 UTC (permalink / raw)
  To: Chris Snook; +Cc: linux-kernel, akpm, jeffpc

Chris Snook <csnook@redhat.com> wrote:

> Patch 1 fixes the case statements to use the symbolic constants in
> include/linux/fs.h, and should not be at all controversial.
>
> Patch 2 adds a SEEK_MAX and uses it to validate user arguments.  This makes
> the code a little cleaner and also enables future extensions (such as
> SEEK_DATA and SEEK_HOLE).  If anyone has a problem with this, please speak up.

Seems reasonable.

Acked-By: David Howells <dhowells@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-02-21 11:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-20 21:57 [PATCH 0/2] use symbolic constants in generic lseek code Chris Snook
2007-02-20 22:01 ` [PATCH 1/2] " Chris Snook
2007-02-20 22:05 ` [PATCH 2/2] use use SEEK_MAX to validate user lseek arguments Chris Snook
2007-02-21 11:38 ` [PATCH 0/2] use symbolic constants in generic lseek code David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.