Commit 6fb5032ebb1c5b852461d64ee33829081de8ca61

Authored by Dmitry Kasatkin
Committed by Mimi Zohar
1 parent c57782c13e

VFS: refactor vfs_read()

integrity_kernel_read() duplicates the file read operations code
in vfs_read(). This patch refactors vfs_read() code creating a
helper function __vfs_read(). It is used by both vfs_read() and
integrity_kernel_read().

Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>

Showing 3 changed files with 22 additions and 13 deletions Side-by-side Diff

... ... @@ -412,6 +412,23 @@
412 412  
413 413 EXPORT_SYMBOL(new_sync_read);
414 414  
  415 +ssize_t __vfs_read(struct file *file, char __user *buf, size_t count,
  416 + loff_t *pos)
  417 +{
  418 + ssize_t ret;
  419 +
  420 + if (file->f_op->read)
  421 + ret = file->f_op->read(file, buf, count, pos);
  422 + else if (file->f_op->aio_read)
  423 + ret = do_sync_read(file, buf, count, pos);
  424 + else if (file->f_op->read_iter)
  425 + ret = new_sync_read(file, buf, count, pos);
  426 + else
  427 + ret = -EINVAL;
  428 +
  429 + return ret;
  430 +}
  431 +
415 432 ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
416 433 {
417 434 ssize_t ret;
... ... @@ -426,12 +443,7 @@
426 443 ret = rw_verify_area(READ, file, pos, count);
427 444 if (ret >= 0) {
428 445 count = ret;
429   - if (file->f_op->read)
430   - ret = file->f_op->read(file, buf, count, pos);
431   - else if (file->f_op->aio_read)
432   - ret = do_sync_read(file, buf, count, pos);
433   - else
434   - ret = new_sync_read(file, buf, count, pos);
  446 + ret = __vfs_read(file, buf, count, pos);
435 447 if (ret > 0) {
436 448 fsnotify_access(file);
437 449 add_rchar(current, ret);
... ... @@ -1527,6 +1527,7 @@
1527 1527 struct iovec *fast_pointer,
1528 1528 struct iovec **ret_pointer);
1529 1529  
  1530 +extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
1530 1531 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
1531 1532 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
1532 1533 extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
security/integrity/iint.c
... ... @@ -184,20 +184,16 @@
184 184 {
185 185 mm_segment_t old_fs;
186 186 char __user *buf = (char __user *)addr;
187   - ssize_t ret = -EINVAL;
  187 + ssize_t ret;
188 188  
189 189 if (!(file->f_mode & FMODE_READ))
190 190 return -EBADF;
191 191  
192 192 old_fs = get_fs();
193 193 set_fs(get_ds());
194   - if (file->f_op->read)
195   - ret = file->f_op->read(file, buf, count, &offset);
196   - else if (file->f_op->aio_read)
197   - ret = do_sync_read(file, buf, count, &offset);
198   - else if (file->f_op->read_iter)
199   - ret = new_sync_read(file, buf, count, &offset);
  194 + ret = __vfs_read(file, buf, count, &offset);
200 195 set_fs(old_fs);
  196 +
201 197 return ret;
202 198 }
203 199