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

Configure Feed

Select the types of activity you want to include in your feed.

Insanity avoidance in /proc

The old /proc interfaces were never updated to use loff_t, and are just
generally broken. Now, we should be using the seq_file interface for
all of the proc files, but converting the legacy functions is more work
than most people care for and has little upside..

But at least we can make the non-LFS rules explicit, rather than just
insanely wrapping the offset or something.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>

+23 -24
+23 -24
fs/proc/generic.c
··· 54 54 ssize_t n, count; 55 55 char *start; 56 56 struct proc_dir_entry * dp; 57 + unsigned long long pos; 58 + 59 + /* 60 + * Gaah, please just use "seq_file" instead. The legacy /proc 61 + * interfaces cut loff_t down to off_t for reads, and ignore 62 + * the offset entirely for writes.. 63 + */ 64 + pos = *ppos; 65 + if (pos > MAX_NON_LFS) 66 + return 0; 67 + if (nbytes > MAX_NON_LFS - pos) 68 + nbytes = MAX_NON_LFS - pos; 57 69 58 70 dp = PDE(inode); 59 71 if (!(page = (char*) __get_free_page(GFP_KERNEL))) ··· 214 202 static loff_t 215 203 proc_file_lseek(struct file *file, loff_t offset, int orig) 216 204 { 217 - lock_kernel(); 218 - 219 - switch (orig) { 220 - case 0: 221 - if (offset < 0) 222 - goto out; 223 - file->f_pos = offset; 224 - unlock_kernel(); 225 - return(file->f_pos); 226 - case 1: 227 - if (offset + file->f_pos < 0) 228 - goto out; 229 - file->f_pos += offset; 230 - unlock_kernel(); 231 - return(file->f_pos); 232 - case 2: 233 - goto out; 234 - default: 235 - goto out; 236 - } 237 - 238 - out: 239 - unlock_kernel(); 240 - return -EINVAL; 205 + loff_t retval = -EINVAL; 206 + switch (orig) { 207 + case 1: 208 + offset += file->f_pos; 209 + /* fallthrough */ 210 + case 0: 211 + if (offset < 0 || offset > MAX_NON_LFS) 212 + break; 213 + file->f_pos = retval = offset; 214 + } 215 + return retval; 241 216 } 242 217 243 218 static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)