Skip to content

Commit 19e7b5f

Browse files
committed
Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull misc vfs updates from Al Viro: "All kinds of misc stuff, without any unifying topic, from various people. Neil's d_anon patch, several bugfixes, introduction of kvmalloc analogue of kmemdup_user(), extending bitfield.h to deal with fixed-endians, assorted cleanups all over the place..." * 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (28 commits) alpha: osf_sys.c: use timespec64 where appropriate alpha: osf_sys.c: fix put_tv32 regression jffs2: Fix use-after-free bug in jffs2_iget()'s error handling path dcache: delete unused d_hash_mask dcache: subtract d_hash_shift from 32 in advance fs/buffer.c: fold init_buffer() into init_page_buffers() fs: fold __inode_permission() into inode_permission() fs: add RWF_APPEND sctp: use vmemdup_user() rather than badly open-coding memdup_user() snd_ctl_elem_init_enum_names(): switch to vmemdup_user() replace_user_tlv(): switch to vmemdup_user() new primitive: vmemdup_user() memdup_user(): switch to GFP_USER eventfd: fold eventfd_ctx_get() into eventfd_ctx_fileget() eventfd: fold eventfd_ctx_read() into eventfd_read() eventfd: convert to use anon_inode_getfd() nfs4file: get rid of pointless include of btrfs.h uvc_v4l2: clean copyin/copyout up vme_user: don't use __copy_..._user() usx2y: don't bother with memdup_user() for 16-byte structure ...
2 parents 26064ea + ce4c253 commit 19e7b5f

28 files changed

Lines changed: 298 additions & 405 deletions

File tree

‎Documentation/filesystems/nfs/Exporting‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,25 @@ a/ A dentry flag DCACHE_DISCONNECTED which is set on
5656
any dentry that might not be part of the proper prefix.
5757
This is set when anonymous dentries are created, and cleared when a
5858
dentry is noticed to be a child of a dentry which is in the proper
59-
prefix.
60-
61-
b/ A per-superblock list "s_anon" of dentries which are the roots of
62-
subtrees that are not in the proper prefix. These dentries, as
63-
well as the proper prefix, need to be released at unmount time. As
64-
these dentries will not be hashed, they are linked together on the
65-
d_hash list_head.
59+
prefix. If the refcount on a dentry with this flag set
60+
becomes zero, the dentry is immediately discarded, rather than being
61+
kept in the dcache. If a dentry that is not already in the dcache
62+
is repeatedly accessed by filehandle (as NFSD might do), an new dentry
63+
will be a allocated for each access, and discarded at the end of
64+
the access.
65+
66+
Note that such a dentry can acquire children, name, ancestors, etc.
67+
without losing DCACHE_DISCONNECTED - that flag is only cleared when
68+
subtree is successfully reconnected to root. Until then dentries
69+
in such subtree are retained only as long as there are references;
70+
refcount reaching zero means immediate eviction, same as for unhashed
71+
dentries. That guarantees that we won't need to hunt them down upon
72+
umount.
73+
74+
b/ A primitive for creation of secondary roots - d_obtain_root(inode).
75+
Those do _not_ bear DCACHE_DISCONNECTED. They are placed on the
76+
per-superblock list (->s_roots), so they can be located at umount
77+
time for eviction purposes.
6678

6779
c/ Helper routines to allocate anonymous dentries, and to help attach
6880
loose directory dentries at lookup time. They are:
@@ -77,7 +89,6 @@ c/ Helper routines to allocate anonymous dentries, and to help attach
7789
(such as an anonymous one created by d_obtain_alias), if appropriate.
7890
It returns NULL when the passed-in dentry is used, following the calling
7991
convention of ->lookup.
80-
8192

8293
Filesystem Issues
8394
-----------------

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -950,22 +950,31 @@ struct itimerval32
950950
};
951951

952952
static inline long
953-
get_tv32(struct timeval *o, struct timeval32 __user *i)
953+
get_tv32(struct timespec64 *o, struct timeval32 __user *i)
954954
{
955955
struct timeval32 tv;
956956
if (copy_from_user(&tv, i, sizeof(struct timeval32)))
957957
return -EFAULT;
958958
o->tv_sec = tv.tv_sec;
959-
o->tv_usec = tv.tv_usec;
959+
o->tv_nsec = tv.tv_usec * NSEC_PER_USEC;
960960
return 0;
961961
}
962962

963963
static inline long
964-
put_tv32(struct timeval32 __user *o, struct timeval *i)
964+
put_tv32(struct timeval32 __user *o, struct timespec64 *i)
965965
{
966966
return copy_to_user(o, &(struct timeval32){
967-
.tv_sec = o->tv_sec,
968-
.tv_usec = o->tv_usec},
967+
.tv_sec = i->tv_sec,
968+
.tv_usec = i->tv_nsec / NSEC_PER_USEC},
969+
sizeof(struct timeval32));
970+
}
971+
972+
static inline long
973+
put_tv_to_tv32(struct timeval32 __user *o, struct timeval *i)
974+
{
975+
return copy_to_user(o, &(struct timeval32){
976+
.tv_sec = i->tv_sec,
977+
.tv_usec = i->tv_usec},
969978
sizeof(struct timeval32));
970979
}
971980

@@ -1004,9 +1013,10 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
10041013
struct timezone __user *, tz)
10051014
{
10061015
if (tv) {
1007-
struct timeval ktv;
1008-
do_gettimeofday(&ktv);
1009-
if (put_tv32(tv, &ktv))
1016+
struct timespec64 kts;
1017+
1018+
ktime_get_real_ts64(&kts);
1019+
if (put_tv32(tv, &kts))
10101020
return -EFAULT;
10111021
}
10121022
if (tz) {
@@ -1019,22 +1029,19 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
10191029
SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
10201030
struct timezone __user *, tz)
10211031
{
1022-
struct timespec64 kts64;
1023-
struct timespec kts;
1032+
struct timespec64 kts;
10241033
struct timezone ktz;
10251034

10261035
if (tv) {
1027-
if (get_tv32((struct timeval *)&kts, tv))
1036+
if (get_tv32(&kts, tv))
10281037
return -EFAULT;
1029-
kts.tv_nsec *= 1000;
1030-
kts64 = timespec_to_timespec64(kts);
10311038
}
10321039
if (tz) {
10331040
if (copy_from_user(&ktz, tz, sizeof(*tz)))
10341041
return -EFAULT;
10351042
}
10361043

1037-
return do_sys_settimeofday64(tv ? &kts64 : NULL, tz ? &ktz : NULL);
1044+
return do_sys_settimeofday64(tv ? &kts : NULL, tz ? &ktz : NULL);
10381045
}
10391046

10401047
asmlinkage long sys_ni_posix_timers(void);
@@ -1083,22 +1090,16 @@ SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
10831090
SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
10841091
struct timeval32 __user *, tvs)
10851092
{
1086-
struct timespec tv[2];
1093+
struct timespec64 tv[2];
10871094

10881095
if (tvs) {
1089-
struct timeval ktvs[2];
1090-
if (get_tv32(&ktvs[0], &tvs[0]) ||
1091-
get_tv32(&ktvs[1], &tvs[1]))
1096+
if (get_tv32(&tv[0], &tvs[0]) ||
1097+
get_tv32(&tv[1], &tvs[1]))
10921098
return -EFAULT;
10931099

1094-
if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
1095-
ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
1100+
if (tv[0].tv_nsec < 0 || tv[0].tv_nsec >= 1000000000 ||
1101+
tv[1].tv_nsec < 0 || tv[1].tv_nsec >= 1000000000)
10961102
return -EINVAL;
1097-
1098-
tv[0].tv_sec = ktvs[0].tv_sec;
1099-
tv[0].tv_nsec = 1000 * ktvs[0].tv_usec;
1100-
tv[1].tv_sec = ktvs[1].tv_sec;
1101-
tv[1].tv_nsec = 1000 * ktvs[1].tv_usec;
11021103
}
11031104

11041105
return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
@@ -1107,19 +1108,18 @@ SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
11071108
SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp,
11081109
fd_set __user *, exp, struct timeval32 __user *, tvp)
11091110
{
1110-
struct timespec end_time, *to = NULL;
1111+
struct timespec64 end_time, *to = NULL;
11111112
if (tvp) {
1112-
struct timeval tv;
1113+
struct timespec64 tv;
11131114
to = &end_time;
11141115

11151116
if (get_tv32(&tv, tvp))
11161117
return -EFAULT;
11171118

1118-
if (tv.tv_sec < 0 || tv.tv_usec < 0)
1119+
if (tv.tv_sec < 0 || tv.tv_nsec < 0)
11191120
return -EINVAL;
11201121

1121-
if (poll_select_set_timeout(to, tv.tv_sec,
1122-
tv.tv_usec * NSEC_PER_USEC))
1122+
if (poll_select_set_timeout(to, tv.tv_sec, tv.tv_nsec))
11231123
return -EINVAL;
11241124

11251125
}
@@ -1192,9 +1192,9 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
11921192
return -EFAULT;
11931193
if (!ur)
11941194
return err;
1195-
if (put_tv32(&ur->ru_utime, &r.ru_utime))
1195+
if (put_tv_to_tv32(&ur->ru_utime, &r.ru_utime))
11961196
return -EFAULT;
1197-
if (put_tv32(&ur->ru_stime, &r.ru_stime))
1197+
if (put_tv_to_tv32(&ur->ru_stime, &r.ru_stime))
11981198
return -EFAULT;
11991199
if (copy_to_user(&ur->ru_maxrss, &r.ru_maxrss,
12001200
sizeof(struct rusage32) - offsetof(struct rusage32, ru_maxrss)))
@@ -1210,18 +1210,18 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
12101210
SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
12111211
struct timeval32 __user *, remain)
12121212
{
1213-
struct timeval tmp;
1213+
struct timespec64 tmp;
12141214
unsigned long ticks;
12151215

12161216
if (get_tv32(&tmp, sleep))
12171217
goto fault;
12181218

1219-
ticks = timeval_to_jiffies(&tmp);
1219+
ticks = timespec64_to_jiffies(&tmp);
12201220

12211221
ticks = schedule_timeout_interruptible(ticks);
12221222

12231223
if (remain) {
1224-
jiffies_to_timeval(ticks, &tmp);
1224+
jiffies_to_timespec64(ticks, &tmp);
12251225
if (put_tv32(remain, &tmp))
12261226
goto fault;
12271227
}
@@ -1280,7 +1280,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
12801280
if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
12811281
(copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) -
12821282
offsetof(struct timex32, tick))) ||
1283-
(put_tv32(&txc_p->time, &txc.time)))
1283+
(put_tv_to_tv32(&txc_p->time, &txc.time)))
12841284
return -EFAULT;
12851285

12861286
return ret;

‎drivers/gpu/drm/r128/r128_state.c‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -982,25 +982,14 @@ static int r128_cce_dispatch_write_pixels(struct drm_device *dev,
982982

983983
xbuf_size = count * sizeof(*x);
984984
ybuf_size = count * sizeof(*y);
985-
x = kmalloc(xbuf_size, GFP_KERNEL);
986-
if (x == NULL)
987-
return -ENOMEM;
988-
y = kmalloc(ybuf_size, GFP_KERNEL);
989-
if (y == NULL) {
990-
kfree(x);
991-
return -ENOMEM;
992-
}
993-
if (copy_from_user(x, depth->x, xbuf_size)) {
994-
kfree(x);
995-
kfree(y);
996-
return -EFAULT;
997-
}
998-
if (copy_from_user(y, depth->y, xbuf_size)) {
985+
x = memdup_user(depth->x, xbuf_size);
986+
if (IS_ERR(x))
987+
return PTR_ERR(x);
988+
y = memdup_user(depth->y, ybuf_size);
989+
if (IS_ERR(y)) {
999990
kfree(x);
1000-
kfree(y);
1001-
return -EFAULT;
991+
return PTR_ERR(y);
1002992
}
1003-
1004993
buffer_size = depth->n * sizeof(u32);
1005994
buffer = memdup_user(depth->buffer, buffer_size);
1006995
if (IS_ERR(buffer)) {

‎drivers/media/usb/uvc/uvc_v4l2.c‎

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,36 +1284,30 @@ struct uvc_xu_control_mapping32 {
12841284
static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
12851285
const struct uvc_xu_control_mapping32 __user *up)
12861286
{
1287-
compat_caddr_t p;
1287+
struct uvc_xu_control_mapping32 *p = (void *)kp;
1288+
compat_caddr_t info;
1289+
u32 count;
12881290

1289-
if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
1290-
__copy_from_user(kp, up, offsetof(typeof(*up), menu_info)) ||
1291-
__get_user(kp->menu_count, &up->menu_count))
1291+
if (copy_from_user(p, up, sizeof(*p)))
12921292
return -EFAULT;
12931293

1294-
memset(kp->reserved, 0, sizeof(kp->reserved));
1295-
1296-
if (kp->menu_count == 0) {
1297-
kp->menu_info = NULL;
1298-
return 0;
1299-
}
1300-
1301-
if (__get_user(p, &up->menu_info))
1302-
return -EFAULT;
1303-
kp->menu_info = compat_ptr(p);
1294+
count = p->menu_count;
1295+
info = p->menu_info;
13041296

1297+
memset(kp->reserved, 0, sizeof(kp->reserved));
1298+
kp->menu_info = count ? compat_ptr(info) : NULL;
1299+
kp->menu_count = count;
13051300
return 0;
13061301
}
13071302

13081303
static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
13091304
struct uvc_xu_control_mapping32 __user *up)
13101305
{
1311-
if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
1312-
__copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
1313-
__put_user(kp->menu_count, &up->menu_count))
1306+
if (copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
1307+
put_user(kp->menu_count, &up->menu_count))
13141308
return -EFAULT;
13151309

1316-
if (__clear_user(up->reserved, sizeof(up->reserved)))
1310+
if (clear_user(up->reserved, sizeof(up->reserved)))
13171311
return -EFAULT;
13181312

13191313
return 0;
@@ -1330,31 +1324,26 @@ struct uvc_xu_control_query32 {
13301324
static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
13311325
const struct uvc_xu_control_query32 __user *up)
13321326
{
1333-
compat_caddr_t p;
1327+
struct uvc_xu_control_query32 v;
13341328

1335-
if (!access_ok(VERIFY_READ, up, sizeof(*up)) ||
1336-
__copy_from_user(kp, up, offsetof(typeof(*up), data)))
1329+
if (copy_from_user(&v, up, sizeof(v)))
13371330
return -EFAULT;
13381331

1339-
if (kp->size == 0) {
1340-
kp->data = NULL;
1341-
return 0;
1342-
}
1343-
1344-
if (__get_user(p, &up->data))
1345-
return -EFAULT;
1346-
kp->data = compat_ptr(p);
1347-
1332+
*kp = (struct uvc_xu_control_query){
1333+
.unit = v.unit,
1334+
.selector = v.selector,
1335+
.query = v.query,
1336+
.size = v.size,
1337+
.data = v.size ? compat_ptr(v.data) : NULL
1338+
};
13481339
return 0;
13491340
}
13501341

13511342
static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
13521343
struct uvc_xu_control_query32 __user *up)
13531344
{
1354-
if (!access_ok(VERIFY_WRITE, up, sizeof(*up)) ||
1355-
__copy_to_user(up, kp, offsetof(typeof(*up), data)))
1345+
if (copy_to_user(up, kp, offsetof(typeof(*up), data)))
13561346
return -EFAULT;
1357-
13581347
return 0;
13591348
}
13601349

‎drivers/staging/lustre/lustre/llite/llite_internal.h‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,15 +1296,7 @@ static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
12961296
spin_lock_nested(&dentry->d_lock,
12971297
nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
12981298
ll_d2d(dentry)->lld_invalid = 1;
1299-
/*
1300-
* We should be careful about dentries created by d_obtain_alias().
1301-
* These dentries are not put in the dentry tree, instead they are
1302-
* linked to sb->s_anon through dentry->d_hash.
1303-
* shrink_dcache_for_umount() shrinks the tree and sb->s_anon list.
1304-
* If we unhashed such a dentry, unmount would not be able to find
1305-
* it and busy inodes would be reported.
1306-
*/
1307-
if (d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
1299+
if (d_count(dentry) == 0)
13081300
__d_drop(dentry);
13091301
spin_unlock(&dentry->d_lock);
13101302
}

‎drivers/staging/vme/devices/vme_user.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
134134
if (copied < 0)
135135
return (int)copied;
136136

137-
if (__copy_to_user(buf, image[minor].kern_buf, (unsigned long)copied))
137+
if (copy_to_user(buf, image[minor].kern_buf, (unsigned long)copied))
138138
return -EFAULT;
139139

140140
return copied;
@@ -146,7 +146,7 @@ static ssize_t resource_from_user(unsigned int minor, const char __user *buf,
146146
if (count > image[minor].size_buf)
147147
count = image[minor].size_buf;
148148

149-
if (__copy_from_user(image[minor].kern_buf, buf, (unsigned long)count))
149+
if (copy_from_user(image[minor].kern_buf, buf, (unsigned long)count))
150150
return -EFAULT;
151151

152152
return vme_master_write(image[minor].resource, image[minor].kern_buf,
@@ -159,7 +159,7 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
159159
void *image_ptr;
160160

161161
image_ptr = image[minor].kern_buf + *ppos;
162-
if (__copy_to_user(buf, image_ptr, (unsigned long)count))
162+
if (copy_to_user(buf, image_ptr, (unsigned long)count))
163163
return -EFAULT;
164164

165165
return count;
@@ -171,7 +171,7 @@ static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
171171
void *image_ptr;
172172

173173
image_ptr = image[minor].kern_buf + *ppos;
174-
if (__copy_from_user(image_ptr, buf, (unsigned long)count))
174+
if (copy_from_user(image_ptr, buf, (unsigned long)count))
175175
return -EFAULT;
176176

177177
return count;

0 commit comments

Comments
 (0)