hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/fs/fcntl.c
....@@ -148,12 +148,17 @@
148148
149149 pid_t f_getown(struct file *filp)
150150 {
151
- pid_t pid;
152
- read_lock(&filp->f_owner.lock);
153
- pid = pid_vnr(filp->f_owner.pid);
154
- if (filp->f_owner.pid_type == PIDTYPE_PGID)
155
- pid = -pid;
156
- read_unlock(&filp->f_owner.lock);
151
+ pid_t pid = 0;
152
+
153
+ read_lock_irq(&filp->f_owner.lock);
154
+ rcu_read_lock();
155
+ if (pid_task(filp->f_owner.pid, filp->f_owner.pid_type)) {
156
+ pid = pid_vnr(filp->f_owner.pid);
157
+ if (filp->f_owner.pid_type == PIDTYPE_PGID)
158
+ pid = -pid;
159
+ }
160
+ rcu_read_unlock();
161
+ read_unlock_irq(&filp->f_owner.lock);
157162 return pid;
158163 }
159164
....@@ -200,11 +205,14 @@
200205 static int f_getown_ex(struct file *filp, unsigned long arg)
201206 {
202207 struct f_owner_ex __user *owner_p = (void __user *)arg;
203
- struct f_owner_ex owner;
208
+ struct f_owner_ex owner = {};
204209 int ret = 0;
205210
206
- read_lock(&filp->f_owner.lock);
207
- owner.pid = pid_vnr(filp->f_owner.pid);
211
+ read_lock_irq(&filp->f_owner.lock);
212
+ rcu_read_lock();
213
+ if (pid_task(filp->f_owner.pid, filp->f_owner.pid_type))
214
+ owner.pid = pid_vnr(filp->f_owner.pid);
215
+ rcu_read_unlock();
208216 switch (filp->f_owner.pid_type) {
209217 case PIDTYPE_PID:
210218 owner.type = F_OWNER_TID;
....@@ -223,7 +231,7 @@
223231 ret = -EINVAL;
224232 break;
225233 }
226
- read_unlock(&filp->f_owner.lock);
234
+ read_unlock_irq(&filp->f_owner.lock);
227235
228236 if (!ret) {
229237 ret = copy_to_user(owner_p, &owner, sizeof(owner));
....@@ -241,10 +249,10 @@
241249 uid_t src[2];
242250 int err;
243251
244
- read_lock(&filp->f_owner.lock);
252
+ read_lock_irq(&filp->f_owner.lock);
245253 src[0] = from_kuid(user_ns, filp->f_owner.uid);
246254 src[1] = from_kuid(user_ns, filp->f_owner.euid);
247
- read_unlock(&filp->f_owner.lock);
255
+ read_unlock_irq(&filp->f_owner.lock);
248256
249257 err = put_user(src[0], &dst[0]);
250258 err |= put_user(src[1], &dst[1]);
....@@ -261,7 +269,7 @@
261269 static bool rw_hint_valid(enum rw_hint hint)
262270 {
263271 switch (hint) {
264
- case RWF_WRITE_LIFE_NOT_SET:
272
+ case RWH_WRITE_LIFE_NOT_SET:
265273 case RWH_WRITE_LIFE_NONE:
266274 case RWH_WRITE_LIFE_SHORT:
267275 case RWH_WRITE_LIFE_MEDIUM:
....@@ -277,7 +285,7 @@
277285 unsigned long arg)
278286 {
279287 struct inode *inode = file_inode(file);
280
- u64 *argp = (u64 __user *)arg;
288
+ u64 __user *argp = (u64 __user *)arg;
281289 enum rw_hint hint;
282290 u64 h;
283291
....@@ -362,7 +370,7 @@
362370 case F_OFD_SETLK:
363371 case F_OFD_SETLKW:
364372 #endif
365
- /* Fallthrough */
373
+ fallthrough;
366374 case F_SETLK:
367375 case F_SETLKW:
368376 if (copy_from_user(&flock, argp, sizeof(flock)))
....@@ -735,8 +743,9 @@
735743 return;
736744
737745 switch (signum) {
738
- siginfo_t si;
739
- default:
746
+ default: {
747
+ kernel_siginfo_t si;
748
+
740749 /* Queue a rt signal with the appropriate fd as its
741750 value. We use SI_SIGIO as the source, not
742751 SI_KERNEL, since kernel signals always get
....@@ -769,7 +778,8 @@
769778 si.si_fd = fd;
770779 if (!do_send_sig_info(signum, &si, p, type))
771780 break;
772
- /* fall-through: fall back on the old plain SIGIO signal */
781
+ }
782
+ fallthrough; /* fall back on the old plain SIGIO signal */
773783 case 0:
774784 do_send_sig_info(SIGIO, SEND_SIG_PRIV, p, type);
775785 }