PATCH: O_NOFOLLOW? (was "Linux 2.1.125 doesn't dump core on SIGSEGV")

Chris Wedgwood (chris@cybernet.co.nz)
Wed, 21 Oct 1998 13:04:50 +1300


--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii

On Wed, Oct 21, 1998 at 12:28:01AM +0100, David Woodhouse wrote:

> I suppose I should just try it.

OK, this implements O_NOFOLLOW - you must as O_NOFOLLOW to
asm/fcntl.h though, which is arch. specific and not in this patch as
I have no idea what sane value would be.

Please pick holes in this.

I've tested this ever so slightly, and it does appear to work... so
if someone can say `yes - this makes sense' I'll make another patch
with the coredump fix proper.

I'm still no entriely sure how to fix the coredump situation, I guess
we just fstat after the open, and if nlink > 1, refuse to dump core.
That way hard links won't screw us.

-cw

--SUOF0GtieIMvvwua
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nofollow.patch"

--- fs/namei.c.orig Wed Oct 21 12:13:30 1998
+++ fs/namei.c Wed Oct 21 13:00:14 1998
@@ -544,8 +544,23 @@
*/
#define no_follow(f) (((f) & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
#define opendir(f) ((f) & O_DIRECTORY)
-#define lookup_flags(f) \
- (no_follow(f) ? 0 : opendir(f) ? (LOOKUP_FOLLOW | LOOKUP_DIRECTORY) : LOOKUP_FOLLOW)
+
+
+/* my brain didn't grok the macro initially... -cw */
+
+static inline int mk_lkupflags(int f)
+{
+ if((f) & O_NOFOLLOW)
+ return 0;
+
+ if(no_follow(f))
+ return 0;
+
+ if(opendir(f))
+ return LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
+
+ return LOOKUP_FOLLOW;
+}

/*
* open_namei()
@@ -569,10 +584,15 @@
mode &= S_IALLUGO & ~current->fs->umask;
mode |= S_IFREG;

- dentry = lookup_dentry(pathname, NULL, lookup_flags(flag));
+ dentry = lookup_dentry(pathname,NULL,mk_lkupflags(flag));
if (IS_ERR(dentry))
return dentry;

+ if(dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)){
+ error = -EACCES;
+ goto exit;
+ }
+
acc_mode = ACC_MODE(flag);
if (flag & O_CREAT) {
struct dentry *dir;

--SUOF0GtieIMvvwua--

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