Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

smackfs: remove redundant lock, fix open(,O_RDWR)

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>

authored by

Ahmed S. Darwish and committed by
Linus Torvalds
cb622bbb 58336114

+2 -33
+2 -33
security/smack/smackfs.c
··· 74 74 #define SEQ_READ_FINISHED 1 75 75 76 76 /* 77 - * Disable concurrent writing open() operations 78 - */ 79 - static struct semaphore smack_write_sem; 80 - 81 - /* 82 77 * Values for parsing cipso rules 83 78 * SMK_DIGITLEN: Length of a digit field in a rule. 84 79 * SMK_CIPSOMIN: Minimum possible cipso rule length. ··· 163 168 */ 164 169 static int smk_open_load(struct inode *inode, struct file *file) 165 170 { 166 - if ((file->f_flags & O_ACCMODE) == O_RDONLY) 167 - return seq_open(file, &load_seq_ops); 168 - 169 - if (down_interruptible(&smack_write_sem)) 170 - return -ERESTARTSYS; 171 - 172 - return 0; 173 - } 174 - 175 - /** 176 - * smk_release_load - release() for /smack/load 177 - * @inode: inode structure representing file 178 - * @file: "load" file pointer 179 - * 180 - * For a reading session, use the seq_file release 181 - * implementation. 182 - * Otherwise, we are at the end of a writing session so 183 - * clean everything up. 184 - */ 185 - static int smk_release_load(struct inode *inode, struct file *file) 186 - { 187 - if ((file->f_flags & O_ACCMODE) == O_RDONLY) 188 - return seq_release(inode, file); 189 - 190 - up(&smack_write_sem); 191 - return 0; 171 + return seq_open(file, &load_seq_ops); 192 172 } 193 173 194 174 /** ··· 311 341 .read = seq_read, 312 342 .llseek = seq_lseek, 313 343 .write = smk_write_load, 314 - .release = smk_release_load, 344 + .release = seq_release, 315 345 }; 316 346 317 347 /** ··· 981 1011 } 982 1012 } 983 1013 984 - sema_init(&smack_write_sem, 1); 985 1014 smk_cipso_doi(); 986 1015 smk_unlbl_ambient(NULL); 987 1016