Commit 3bad2f1c authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.misc-set_fs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull misc user access cleanups from Al Viro:
 "The first pile is assorted getting rid of cargo-culted access_ok(),
  cargo-culted set_fs() and field-by-field copyouts.

  The same description applies to a lot of stuff in other branches -
  this is just the stuff that didn't fit into a more specific topical
  branch"

* 'work.misc-set_fs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  Switch flock copyin/copyout primitives to copy_{from,to}_user()
  fs/fcntl: return -ESRCH in f_setown when pid/pgid can't be found
  fs/fcntl: f_setown, avoid undefined behaviour
  fs/fcntl: f_setown, allow returning error
  lpfc debugfs: get rid of pointless access_ok()
  adb: get rid of pointless access_ok()
  isdn: get rid of pointless access_ok()
  compat statfs: switch to copy_to_user()
  fs/locks: don't mess with the address limit in compat_fcntl64
  nfsd_readlink(): switch to vfs_get_link()
  drbd: ->sendpage() never needed set_fs()
  fs/locks: pass kernel struct flock to fcntl_getlk/setlk
  fs: locks: Fix some troubles at kernel-doc comments
parents b4b8cbf6 8c6657cb
...@@ -1551,7 +1551,6 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa ...@@ -1551,7 +1551,6 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa
int offset, size_t size, unsigned msg_flags) int offset, size_t size, unsigned msg_flags)
{ {
struct socket *socket = peer_device->connection->data.socket; struct socket *socket = peer_device->connection->data.socket;
mm_segment_t oldfs = get_fs();
int len = size; int len = size;
int err = -EIO; int err = -EIO;
...@@ -1566,7 +1565,6 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa ...@@ -1566,7 +1565,6 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa
msg_flags |= MSG_NOSIGNAL; msg_flags |= MSG_NOSIGNAL;
drbd_update_congested(peer_device->connection); drbd_update_congested(peer_device->connection);
set_fs(KERNEL_DS);
do { do {
int sent; int sent;
...@@ -1586,7 +1584,6 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa ...@@ -1586,7 +1584,6 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa
len -= sent; len -= sent;
offset += sent; offset += sent;
} while (len > 0 /* THINK && device->cstate >= C_CONNECTED*/); } while (len > 0 /* THINK && device->cstate >= C_CONNECTED*/);
set_fs(oldfs);
clear_bit(NET_CONGESTED, &peer_device->connection->flags); clear_bit(NET_CONGESTED, &peer_device->connection->flags);
if (len == 0) { if (len == 0) {
......
...@@ -1304,9 +1304,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg) ...@@ -1304,9 +1304,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
if (arg) { if (arg) {
ulong __user *p = argp; ulong __user *p = argp;
int i; int i;
if (!access_ok(VERIFY_WRITE, p,
sizeof(ulong) * ISDN_MAX_CHANNELS * 2))
return -EFAULT;
for (i = 0; i < ISDN_MAX_CHANNELS; i++) { for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
put_user(dev->ibytes[i], p++); put_user(dev->ibytes[i], p++);
put_user(dev->obytes[i], p++); put_user(dev->obytes[i], p++);
...@@ -1540,11 +1537,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg) ...@@ -1540,11 +1537,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
char __user *p = argp; char __user *p = argp;
int i; int i;
if (!access_ok(VERIFY_WRITE, argp,
(ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
* ISDN_MAX_CHANNELS))
return -EFAULT;
for (i = 0; i < ISDN_MAX_CHANNELS; i++) { for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
if (copy_to_user(p, dev->mdm.info[i].emu.profile, if (copy_to_user(p, dev->mdm.info[i].emu.profile,
ISDN_MODEM_NUMREG)) ISDN_MODEM_NUMREG))
...@@ -1567,11 +1559,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg) ...@@ -1567,11 +1559,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
char __user *p = argp; char __user *p = argp;
int i; int i;
if (!access_ok(VERIFY_READ, argp,
(ISDN_MODEM_NUMREG + ISDN_MSNLEN + ISDN_LMSNLEN)
* ISDN_MAX_CHANNELS))
return -EFAULT;
for (i = 0; i < ISDN_MAX_CHANNELS; i++) { for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
if (copy_from_user(dev->mdm.info[i].emu.profile, p, if (copy_from_user(dev->mdm.info[i].emu.profile, p,
ISDN_MODEM_NUMREG)) ISDN_MODEM_NUMREG))
...@@ -1617,8 +1604,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg) ...@@ -1617,8 +1604,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
int j = 0; int j = 0;
while (1) { while (1) {
if (!access_ok(VERIFY_READ, p, 1))
return -EFAULT;
get_user(bname[j], p++); get_user(bname[j], p++);
switch (bname[j]) { switch (bname[j]) {
case '\0': case '\0':
...@@ -1685,9 +1670,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg) ...@@ -1685,9 +1670,6 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
drvidx = 0; drvidx = 0;
if (drvidx == -1) if (drvidx == -1)
return -ENODEV; return -ENODEV;
if (!access_ok(VERIFY_WRITE, argp,
sizeof(isdn_ioctl_struct)))
return -EFAULT;
c.driver = drvidx; c.driver = drvidx;
c.command = ISDN_CMD_IOCTL; c.command = ISDN_CMD_IOCTL;
c.arg = cmd; c.arg = cmd;
......
...@@ -795,9 +795,6 @@ isdn_ppp_read(int min, struct file *file, char __user *buf, int count) ...@@ -795,9 +795,6 @@ isdn_ppp_read(int min, struct file *file, char __user *buf, int count)
if (!(is->state & IPPP_OPEN)) if (!(is->state & IPPP_OPEN))
return 0; return 0;
if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
spin_lock_irqsave(&is->buflock, flags); spin_lock_irqsave(&is->buflock, flags);
b = is->first->next; b = is->first->next;
save_buf = b->buf; save_buf = b->buf;
...@@ -2014,9 +2011,6 @@ isdn_ppp_dev_ioctl_stats(int slot, struct ifreq *ifr, struct net_device *dev) ...@@ -2014,9 +2011,6 @@ isdn_ppp_dev_ioctl_stats(int slot, struct ifreq *ifr, struct net_device *dev)
struct ppp_stats t; struct ppp_stats t;
isdn_net_local *lp = netdev_priv(dev); isdn_net_local *lp = netdev_priv(dev);
if (!access_ok(VERIFY_WRITE, res, sizeof(struct ppp_stats)))
return -EFAULT;
/* build a temporary stat struct and copy it to user space */ /* build a temporary stat struct and copy it to user space */
memset(&t, 0, sizeof(struct ppp_stats)); memset(&t, 0, sizeof(struct ppp_stats));
......
...@@ -1142,8 +1142,6 @@ isdnloop_command(isdn_ctrl *c, isdnloop_card *card) ...@@ -1142,8 +1142,6 @@ isdnloop_command(isdn_ctrl *c, isdnloop_card *card)
case ISDNLOOP_IOCTL_DEBUGVAR: case ISDNLOOP_IOCTL_DEBUGVAR:
return (ulong) card; return (ulong) card;
case ISDNLOOP_IOCTL_STARTUP: case ISDNLOOP_IOCTL_STARTUP:
if (!access_ok(VERIFY_READ, (void *) a, sizeof(isdnloop_sdef)))
return -EFAULT;
return isdnloop_start(card, (isdnloop_sdef *) a); return isdnloop_start(card, (isdnloop_sdef *) a);
break; break;
case ISDNLOOP_IOCTL_ADDCARD: case ISDNLOOP_IOCTL_ADDCARD:
......
...@@ -723,8 +723,6 @@ static ssize_t adb_read(struct file *file, char __user *buf, ...@@ -723,8 +723,6 @@ static ssize_t adb_read(struct file *file, char __user *buf,
return -EINVAL; return -EINVAL;
if (count > sizeof(req->reply)) if (count > sizeof(req->reply))
count = sizeof(req->reply); count = sizeof(req->reply);
if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
req = NULL; req = NULL;
spin_lock_irqsave(&state->lock, flags); spin_lock_irqsave(&state->lock, flags);
...@@ -781,8 +779,6 @@ static ssize_t adb_write(struct file *file, const char __user *buf, ...@@ -781,8 +779,6 @@ static ssize_t adb_write(struct file *file, const char __user *buf,
return -EINVAL; return -EINVAL;
if (adb_controller == NULL) if (adb_controller == NULL)
return -ENXIO; return -ENXIO;
if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT;
req = kmalloc(sizeof(struct adb_request), req = kmalloc(sizeof(struct adb_request),
GFP_KERNEL); GFP_KERNEL);
......
...@@ -1949,10 +1949,6 @@ lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf, ...@@ -1949,10 +1949,6 @@ lpfc_debugfs_nvmestat_write(struct file *file, const char __user *buf,
if (nbytes > 64) if (nbytes > 64)
nbytes = 64; nbytes = 64;
/* Protect copy from user */
if (!access_ok(VERIFY_READ, buf, nbytes))
return -EFAULT;
memset(mybuf, 0, sizeof(mybuf)); memset(mybuf, 0, sizeof(mybuf));
if (copy_from_user(mybuf, buf, nbytes)) if (copy_from_user(mybuf, buf, nbytes))
...@@ -2037,10 +2033,6 @@ lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf, ...@@ -2037,10 +2033,6 @@ lpfc_debugfs_nvmektime_write(struct file *file, const char __user *buf,
if (nbytes > 64) if (nbytes > 64)
nbytes = 64; nbytes = 64;
/* Protect copy from user */
if (!access_ok(VERIFY_READ, buf, nbytes))
return -EFAULT;
memset(mybuf, 0, sizeof(mybuf)); memset(mybuf, 0, sizeof(mybuf));
if (copy_from_user(mybuf, buf, nbytes)) if (copy_from_user(mybuf, buf, nbytes))
...@@ -2169,10 +2161,6 @@ lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf, ...@@ -2169,10 +2161,6 @@ lpfc_debugfs_nvmeio_trc_write(struct file *file, const char __user *buf,
if (nbytes > 64) if (nbytes > 64)
nbytes = 64; nbytes = 64;
/* Protect copy from user */
if (!access_ok(VERIFY_READ, buf, nbytes))
return -EFAULT;
memset(mybuf, 0, sizeof(mybuf)); memset(mybuf, 0, sizeof(mybuf));
if (copy_from_user(mybuf, buf, nbytes)) if (copy_from_user(mybuf, buf, nbytes))
...@@ -2280,10 +2268,6 @@ lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf, ...@@ -2280,10 +2268,6 @@ lpfc_debugfs_cpucheck_write(struct file *file, const char __user *buf,
if (nbytes > 64) if (nbytes > 64)
nbytes = 64; nbytes = 64;
/* Protect copy from user */
if (!access_ok(VERIFY_READ, buf, nbytes))
return -EFAULT;
memset(mybuf, 0, sizeof(mybuf)); memset(mybuf, 0, sizeof(mybuf));
if (copy_from_user(mybuf, buf, nbytes)) if (copy_from_user(mybuf, buf, nbytes))
...@@ -2354,10 +2338,6 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes, ...@@ -2354,10 +2338,6 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes,
int i; int i;
size_t bsize; size_t bsize;
/* Protect copy from user */
if (!access_ok(VERIFY_READ, buf, nbytes))
return -EFAULT;
memset(mybuf, 0, sizeof(mybuf)); memset(mybuf, 0, sizeof(mybuf));
memset(idiag_cmd, 0, sizeof(*idiag_cmd)); memset(idiag_cmd, 0, sizeof(*idiag_cmd));
bsize = min(nbytes, (sizeof(mybuf)-1)); bsize = min(nbytes, (sizeof(mybuf)-1));
......
This diff is collapsed.
...@@ -1858,8 +1858,8 @@ EXPORT_SYMBOL(generic_setlease); ...@@ -1858,8 +1858,8 @@ EXPORT_SYMBOL(generic_setlease);
* *
* Call this to establish a lease on the file. The "lease" argument is not * Call this to establish a lease on the file. The "lease" argument is not
* used for F_UNLCK requests and may be NULL. For commands that set or alter * used for F_UNLCK requests and may be NULL. For commands that set or alter
* an existing lease, the (*lease)->fl_lmops->lm_break operation must be set; * an existing lease, the ``(*lease)->fl_lmops->lm_break`` operation must be
* if not, this function will return -ENOLCK (and generate a scary-looking * set; if not, this function will return -ENOLCK (and generate a scary-looking
* stack trace). * stack trace).
* *
* The "priv" pointer is passed directly to the lm_setup function as-is. It * The "priv" pointer is passed directly to the lm_setup function as-is. It
...@@ -1972,15 +1972,13 @@ EXPORT_SYMBOL(locks_lock_inode_wait); ...@@ -1972,15 +1972,13 @@ EXPORT_SYMBOL(locks_lock_inode_wait);
* @cmd: the type of lock to apply. * @cmd: the type of lock to apply.
* *
* Apply a %FL_FLOCK style lock to an open file descriptor. * Apply a %FL_FLOCK style lock to an open file descriptor.
* The @cmd can be one of * The @cmd can be one of:
* *
* %LOCK_SH -- a shared lock. * - %LOCK_SH -- a shared lock.
* * - %LOCK_EX -- an exclusive lock.
* %LOCK_EX -- an exclusive lock. * - %LOCK_UN -- remove an existing lock.
* * - %LOCK_MAND -- a 'mandatory' flock.
* %LOCK_UN -- remove an existing lock. * This exists to emulate Windows Share Modes.
*
* %LOCK_MAND -- a `mandatory' flock. This exists to emulate Windows Share Modes.
* *
* %LOCK_MAND can be combined with %LOCK_READ or %LOCK_WRITE to allow other * %LOCK_MAND can be combined with %LOCK_READ or %LOCK_WRITE to allow other
* processes read and write access respectively. * processes read and write access respectively.
...@@ -2086,26 +2084,22 @@ static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl) ...@@ -2086,26 +2084,22 @@ static void posix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl)
/* Report the first existing lock that would conflict with l. /* Report the first existing lock that would conflict with l.
* This implements the F_GETLK command of fcntl(). * This implements the F_GETLK command of fcntl().
*/ */
int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l) int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
{ {
struct file_lock file_lock; struct file_lock file_lock;
struct flock flock;
int error; int error;
error = -EFAULT;
if (copy_from_user(&flock, l, sizeof(flock)))
goto out;
error = -EINVAL; error = -EINVAL;
if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK)) if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK)
goto out; goto out;
error = flock_to_posix_lock(filp, &file_lock, &flock); error = flock_to_posix_lock(filp, &file_lock, flock);
if (error) if (error)
goto out; goto out;
if (cmd == F_OFD_GETLK) { if (cmd == F_OFD_GETLK) {
error = -EINVAL; error = -EINVAL;
if (flock.l_pid != 0) if (flock->l_pid != 0)
goto out; goto out;
cmd = F_GETLK; cmd = F_GETLK;
...@@ -2117,15 +2111,12 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l) ...@@ -2117,15 +2111,12 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock __user *l)
if (error) if (error)
goto out; goto out;
flock.l_type = file_lock.fl_type; flock->l_type = file_lock.fl_type;
if (file_lock.fl_type != F_UNLCK) { if (file_lock.fl_type != F_UNLCK) {
error = posix_lock_to_flock(&flock, &file_lock); error = posix_lock_to_flock(flock, &file_lock);
if (error) if (error)
goto rel_priv; goto rel_priv;
} }
error = -EFAULT;
if (!copy_to_user(l, &flock, sizeof(flock)))
error = 0;
rel_priv: rel_priv:
locks_release_private(&file_lock); locks_release_private(&file_lock);
out: out:
...@@ -2218,26 +2209,16 @@ check_fmode_for_setlk(struct file_lock *fl) ...@@ -2218,26 +2209,16 @@ check_fmode_for_setlk(struct file_lock *fl)
* This implements both the F_SETLK and F_SETLKW commands of fcntl(). * This implements both the F_SETLK and F_SETLKW commands of fcntl().
*/ */
int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
struct flock __user *l) struct flock *flock)
{ {
struct file_lock *file_lock = locks_alloc_lock(); struct file_lock *file_lock = locks_alloc_lock();
struct flock flock; struct inode *inode = locks_inode(filp);
struct inode *inode;
struct file *f; struct file *f;
int error; int error;
if (file_lock == NULL) if (file_lock == NULL)
return -ENOLCK; return -ENOLCK;
inode = locks_inode(filp);
/*
* This might block, so we do it before checking the inode.
*/
error = -EFAULT;
if (copy_from_user(&flock, l, sizeof(flock)))
goto out;
/* Don't allow mandatory locks on files that may be memory mapped /* Don't allow mandatory locks on files that may be memory mapped
* and shared. * and shared.
*/ */
...@@ -2246,7 +2227,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2246,7 +2227,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
goto out; goto out;
} }
error = flock_to_posix_lock(filp, file_lock, &flock); error = flock_to_posix_lock(filp, file_lock, flock);
if (error) if (error)
goto out; goto out;
...@@ -2261,7 +2242,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2261,7 +2242,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
switch (cmd) { switch (cmd) {
case F_OFD_SETLK: case F_OFD_SETLK:
error = -EINVAL; error = -EINVAL;
if (flock.l_pid != 0) if (flock->l_pid != 0)
goto out; goto out;
cmd = F_SETLK; cmd = F_SETLK;
...@@ -2270,7 +2251,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2270,7 +2251,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
break; break;
case F_OFD_SETLKW: case F_OFD_SETLKW:
error = -EINVAL; error = -EINVAL;
if (flock.l_pid != 0) if (flock->l_pid != 0)
goto out; goto out;
cmd = F_SETLKW; cmd = F_SETLKW;
...@@ -2315,26 +2296,22 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2315,26 +2296,22 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
/* Report the first existing lock that would conflict with l. /* Report the first existing lock that would conflict with l.
* This implements the F_GETLK command of fcntl(). * This implements the F_GETLK command of fcntl().
*/ */
int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l) int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock)
{ {
struct file_lock file_lock; struct file_lock file_lock;
struct flock64 flock;
int error; int error;
error = -EFAULT;
if (copy_from_user(&flock, l, sizeof(flock)))
goto out;
error = -EINVAL; error = -EINVAL;
if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK)) if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK)
goto out; goto out;
error = flock64_to_posix_lock(filp, &file_lock, &flock); error = flock64_to_posix_lock(filp, &file_lock, flock);
if (error) if (error)
goto out; goto out;
if (cmd == F_OFD_GETLK) { if (cmd == F_OFD_GETLK) {
error = -EINVAL; error = -EINVAL;
if (flock.l_pid != 0) if (flock->l_pid != 0)
goto out; goto out;
cmd = F_GETLK64; cmd = F_GETLK64;
...@@ -2346,13 +2323,9 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l) ...@@ -2346,13 +2323,9 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l)
if (error) if (error)
goto out; goto out;
flock.l_type = file_lock.fl_type; flock->l_type = file_lock.fl_type;
if (file_lock.fl_type != F_UNLCK) if (file_lock.fl_type != F_UNLCK)
posix_lock_to_flock64(&flock, &file_lock); posix_lock_to_flock64(flock, &file_lock);
error = -EFAULT;
if (!copy_to_user(l, &flock, sizeof(flock)))
error = 0;
locks_release_private(&file_lock); locks_release_private(&file_lock);
out: out:
...@@ -2363,26 +2336,16 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l) ...@@ -2363,26 +2336,16 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 __user *l)
* This implements both the F_SETLK and F_SETLKW commands of fcntl(). * This implements both the F_SETLK and F_SETLKW commands of fcntl().
*/ */
int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
struct flock64 __user *l) struct flock64 *flock)
{ {
struct file_lock *file_lock = locks_alloc_lock(); struct file_lock *file_lock = locks_alloc_lock();
struct flock64 flock; struct inode *inode = locks_inode(filp);
struct inode *inode;
struct file *f; struct file *f;
int error; int error;
if (file_lock == NULL) if (file_lock == NULL)
return -ENOLCK; return -ENOLCK;
/*
* This might block, so we do it before checking the inode.
*/
error = -EFAULT;
if (copy_from_user(&flock, l, sizeof(flock)))
goto out;
inode = locks_inode(filp);
/* Don't allow mandatory locks on files that may be memory mapped /* Don't allow mandatory locks on files that may be memory mapped
* and shared. * and shared.
*/ */
...@@ -2391,7 +2354,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2391,7 +2354,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
goto out; goto out;
} }
error = flock64_to_posix_lock(filp, file_lock, &flock); error = flock64_to_posix_lock(filp, file_lock, flock);
if (error) if (error)
goto out; goto out;
...@@ -2406,7 +2369,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2406,7 +2369,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
switch (cmd) { switch (cmd) {
case F_OFD_SETLK: case F_OFD_SETLK:
error = -EINVAL; error = -EINVAL;
if (flock.l_pid != 0) if (flock->l_pid != 0)
goto out; goto out;
cmd = F_SETLK64; cmd = F_SETLK64;
...@@ -2415,7 +2378,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd, ...@@ -2415,7 +2378,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
break; break;
case F_OFD_SETLKW: case F_OFD_SETLKW:
error = -EINVAL; error = -EINVAL;
if (flock.l_pid != 0) if (flock->l_pid != 0)
goto out; goto out;
cmd = F_SETLKW64; cmd = F_SETLKW64;
......
...@@ -1464,41 +1464,34 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, ...@@ -1464,41 +1464,34 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,
__be32 __be32
nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp) nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
{ {
mm_segment_t oldfs;
__be32 err; __be32 err;
int host_err; const char *link;
struct path path; struct path path;
DEFINE_DELAYED_CALL(done);
int len;
err = fh_verify(rqstp, fhp, S_IFLNK, NFSD_MAY_NOP); err = fh_verify(rqstp, fhp, S_IFLNK, NFSD_MAY_NOP);
if (err) if (unlikely(err))
goto out; return err;
path.mnt = fhp->fh_export->ex_path.mnt; path.mnt = fhp->fh_export->ex_path.mnt;
path.dentry = fhp->fh_dentry; path.dentry = fhp->fh_dentry;
err = nfserr_inval; if (unlikely(!d_is_symlink(path.dentry)))
if (!d_is_symlink(path.dentry)) return nfserr_inval;
goto out;
touch_atime(&path); touch_atime(&path);
/* N.B. Why does this call need a get_fs()??
* Remove the set_fs and watch the fireworks:-) --okir
*/
oldfs = get_fs(); set_fs(KERNEL_DS); link = vfs_get_link(path.dentry, &done);
host_err = vfs_readlink(path.dentry, (char __user *)buf, *lenp); if (IS_ERR(link))
set_fs(oldfs); return nfserrno(PTR_ERR(link));
if (host_err < 0) len = strlen(link);
goto out_nfserr; if (len < *lenp)
*lenp = host_err; *lenp = len;
err = 0; memcpy(buf, link, *lenp);
out: do_delayed_call(&done);
return err; return 0;
out_nfserr:
err = nfserrno(host_err);
goto out;
} }
/* /*
......
...@@ -244,6 +244,7 @@ SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf) ...@@ -244,6 +244,7 @@ SYSCALL_DEFINE2(ustat, unsigned, dev, struct ustat __user *, ubuf)
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf) static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *kbuf)
{ {
struct compat_statfs buf;
if (sizeof ubuf->f_blocks == 4) { if (sizeof ubuf->f_blocks == 4) {
if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail | if ((kbuf->f_blocks | kbuf->f_bfree | kbuf->f_bavail |
kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL) kbuf->f_bsize | kbuf->f_frsize) & 0xffffffff00000000ULL)
...@@ -257,20 +258,20 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs * ...@@ -257,20 +258,20 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
&& (kbuf->f_ffree & 0xffffffff00000000ULL)) && (kbuf->f_ffree & 0xffffffff00000000ULL))
return -EOVERFLOW; return -EOVERFLOW;
} }
if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) || memset(&buf, 0, sizeof(struct compat_statfs));
__put_user(kbuf->f_type, &ubuf->f_type) || buf.f_type = kbuf->f_type;
__put_user(kbuf->f_bsize, &ubuf->f_bsize) || buf.f_bsize = kbuf->f_bsize;
__put_user(kbuf->f_blocks, &ubuf->f_blocks) || buf.f_blocks = kbuf->f_blocks;
__put_user(kbuf->f_bfree, &ubuf->f_bfree) || buf.f_bfree = kbuf->f_bfree;
__put_user(kbuf->f_bavail, &ubuf->f_bavail) || buf.f_bavail = kbuf->f_bavail;
__put_user(kbuf->f_files, &ubuf->f_files) || buf.f_files = kbuf->f_files;
__put_user(kbuf->f_ffree, &ubuf->f_ffree) || buf.f_ffree = kbuf->f_ffree;
__put_user(kbuf->f_namelen, &ubuf->f_namelen) || buf.f_namelen = kbuf->f_namelen;
__put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || buf.f_fsid.val[0] = kbuf->f_fsid.val[0];
__put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || buf.f_fsid.val[1] = kbuf->f_fsid.val[1];
__put_user(kbuf->f_frsize, &ubuf->f_frsize) || buf.f_frsize = kbuf->f_frsize;
__put_user(kbuf->f_flags, &ubuf->f_flags) || buf.f_flags = kbuf->f_flags;
__clear_user(ubuf->f_spare, sizeof(ubuf->f_spare))) if (copy_to_user(ubuf, &buf, sizeof(struct compat_statfs)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
...@@ -299,6 +300,7 @@ COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *, ...@@ -299,6 +300,7 @@ COMPAT_SYSCALL_DEFINE2(fstatfs, unsigned int, fd, struct compat_statfs __user *,
static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf) static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstatfs *kbuf)
{ {
struct compat_statfs64 buf;
if (sizeof(ubuf->f_bsize) == 4) { if (sizeof(ubuf->f_bsize) == 4) {
if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen | if ((kbuf->f_type | kbuf->f_bsize | kbuf->f_namelen |
kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL) kbuf->f_frsize | kbuf->f_flags) & 0xffffffff00000000ULL)
...@@ -312,20 +314,20 @@ static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstat ...@@ -312,20 +314,20 @@ static int put_compat_statfs64(struct compat_statfs64 __user *ubuf, struct kstat
&& (kbuf->f_ffree & 0xffffffff00000000ULL)) && (kbuf->f_ffree & 0xffffffff00000000ULL))
return -EOVERFLOW; return -EOVERFLOW;
} }
if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf)) || memset(&buf, 0, sizeof(struct compat_statfs64));
__put_user(kbuf->f_type, &ubuf->f_type) || buf.f_type = kbuf->f_type;
__put_user(kbuf->f_bsize, &ubuf->f_bsize) || buf.f_bsize = kbuf->f_bsize;
__put_user(kbuf->f_blocks, &ubuf->f_blocks) || buf.f_blocks = kbuf->f_blocks;
__put_user(kbuf->f_bfree, &ubuf->f_bfree) || buf.f_bfree = kbuf->f_bfree;
__put_user(kbuf->f_bavail, &ubuf->f_bavail) || buf.f_bavail = kbuf->f_bavail;
__put_user(kbuf->f_files, &ubuf->f_files) || buf.f_files = kbuf->f_files;
__put_user(kbuf->f_ffree, &ubuf->f_ffree) || buf.f_ffree = kbuf->f_ffree;
__put_user(kbuf->f_namelen, &ubuf->f_namelen) || buf.f_namelen = kbuf->f_namelen;
__put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) || buf.f_fsid.val[0] = kbuf->f_fsid.val[0];
__put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) || buf.f_fsid.val[1] = kbuf->f_fsid.val[1];
__put_user(kbuf->f_frsize, &ubuf->f_frsize) || buf.f_frsize = kbuf->f_frsize;
__put_user(kbuf->f_flags, &ubuf->f_flags) || buf.f_flags = kbuf->f_flags;
__clear_user(ubuf->f_spare, sizeof(ubuf->f_spare))) if (copy_to_user(ubuf, &buf, sizeof(struct compat_statfs64)))
return -EFAULT; return -EFAULT;
return 0; return 0;
} }
......
...@@ -1047,14 +1047,14 @@ static inline struct inode *locks_inode(const struct file *f) ...@@ -1047,14 +1047,14 @@ static inline struct inode *locks_inode(const struct file *f)
} }
#ifdef CONFIG_FILE_LOCKING #ifdef CONFIG_FILE_LOCKING
extern int fcntl_getlk(struct file *, unsigned int, struct flock __user *); extern int fcntl_getlk(struct file *, unsigned int, struct flock *);
extern int fcntl_setlk(unsigned int, struct file *, unsigned int, extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
struct flock __user *); struct flock *);
#if BITS_PER_LONG == 32 #if BITS_PER_LONG == 32
extern int fcntl_getlk64(struct file *, unsigned int, struct flock64 __user *); extern int fcntl_getlk64(struct file *, unsigned int, struct flock64 *);
extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
struct flock64 __user *); struct flock64 *);
#endif #endif
extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
...@@ -1258,7 +1258,7 @@ extern void fasync_free(struct fasync_struct *); ...@@ -1258,7 +1258,7 @@ extern void fasync_free(struct fasync_struct *);
extern void kill_fasync(struct fasync_struct **, int, int); extern void kill_fasync(struct fasync_struct **, int, int);
extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force); extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
extern void f_setown(struct file *filp, unsigned long arg, int force); extern int f_setown(struct file *filp, unsigned long arg, int force);
extern void f_delown(struct file *filp); extern void f_delown(struct file *filp);
extern pid_t f_getown(struct file *filp); extern pid_t f_getown(struct file *filp);
extern int send_sigurg(struct fown_struct *fown); extern int send_sigurg(struct fown_struct *fown);
......
...@@ -991,8 +991,7 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) ...@@ -991,8 +991,7 @@ static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
err = -EFAULT; err = -EFAULT;
if (get_user(pid, (int __user *)argp)) if (get_user(pid, (int __user *)argp))
break; break;
f_setown(sock->file, pid, 1); err = f_setown(sock->file, pid, 1);
err = 0;
break; break;
case FIOGETOWN: case FIOGETOWN:
case SIOCGPGRP: case SIOCGPGRP:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment