Skip to content

Commit

Permalink
smackfs: remove redundant lock, fix open(,O_RDWR)
Browse files Browse the repository at this point in the history
Older smackfs was parsing MAC rules by characters, thus a need of locking
write sessions on open() was needed.  This lock is no longer useful now since
each rule is handled by a single write() call.

This is also a bugfix since seq_open() was not called if an open() O_RDWR flag
was given, leading to a seq_read() without an initialized seq_file, thus an
Oops.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
Reported-by: Jonathan Corbet <corbet@lwn.net>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Ahmed S. Darwish authored and Linus Torvalds committed Mar 25, 2008
1 parent 5833611 commit cb622bb
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions security/smack/smackfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ struct smk_list_entry *smack_list;

#define SEQ_READ_FINISHED 1

/*
* Disable concurrent writing open() operations
*/
static struct semaphore smack_write_sem;

/*
* Values for parsing cipso rules
* SMK_DIGITLEN: Length of a digit field in a rule.
Expand Down Expand Up @@ -168,32 +163,7 @@ static struct seq_operations load_seq_ops = {
*/
static int smk_open_load(struct inode *inode, struct file *file)
{
if ((file->f_flags & O_ACCMODE) == O_RDONLY)
return seq_open(file, &load_seq_ops);

if (down_interruptible(&smack_write_sem))
return -ERESTARTSYS;

return 0;
}

/**
* smk_release_load - release() for /smack/load
* @inode: inode structure representing file
* @file: "load" file pointer
*
* For a reading session, use the seq_file release
* implementation.
* Otherwise, we are at the end of a writing session so
* clean everything up.
*/
static int smk_release_load(struct inode *inode, struct file *file)
{
if ((file->f_flags & O_ACCMODE) == O_RDONLY)
return seq_release(inode, file);

up(&smack_write_sem);
return 0;
return seq_open(file, &load_seq_ops);
}

/**
Expand Down Expand Up @@ -341,7 +311,7 @@ static const struct file_operations smk_load_ops = {
.read = seq_read,
.llseek = seq_lseek,
.write = smk_write_load,
.release = smk_release_load,
.release = seq_release,
};

/**
Expand Down Expand Up @@ -1011,7 +981,6 @@ static int __init init_smk_fs(void)
}
}

sema_init(&smack_write_sem, 1);
smk_cipso_doi();
smk_unlbl_ambient(NULL);

Expand Down

0 comments on commit cb622bb

Please sign in to comment.