Skip to content

Commit b891d11

Browse files
committed
Merge tag 'driver-core-6.17-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core
Pull driver core fixes from Danilo Krummrich: - Fix UAF in cgroup pressure polling by using kernfs_get_active_of() to prevent operations on released file descriptors - Fix unresolved intra-doc link in the documentation of struct Device when CONFIG_DRM != y - Update the DMA Rust MAINTAINERS entry * tag 'driver-core-6.17-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core: MAINTAINERS: Update the DMA Rust entry kernfs: Fix UAF in polling when open file is released rust: device: fix unresolved link to drm::Device
2 parents 22f2037 + f6d2900 commit b891d11

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

MAINTAINERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7238,15 +7238,15 @@ F: include/linux/swiotlb.h
72387238
F: kernel/dma/
72397239

72407240
DMA MAPPING HELPERS DEVICE DRIVER API [RUST]
7241-
M: Abdiel Janulgue <[email protected]>
72427241
M: Danilo Krummrich <[email protected]>
7242+
R: Abdiel Janulgue <[email protected]>
72437243
R: Daniel Almeida <[email protected]>
72447244
R: Robin Murphy <[email protected]>
72457245
R: Andreas Hindborg <[email protected]>
72467246
72477247
S: Supported
72487248
W: https://rust-for-linux.com
7249-
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
7249+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git
72507250
F: rust/helpers/dma.c
72517251
F: rust/kernel/dma.rs
72527252
F: samples/rust/rust_dma.rs

fs/kernfs/file.c

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ static struct kernfs_open_node *of_on(struct kernfs_open_file *of)
7070
!list_empty(&of->list));
7171
}
7272

73+
/* Get active reference to kernfs node for an open file */
74+
static struct kernfs_open_file *kernfs_get_active_of(struct kernfs_open_file *of)
75+
{
76+
/* Skip if file was already released */
77+
if (unlikely(of->released))
78+
return NULL;
79+
80+
if (!kernfs_get_active(of->kn))
81+
return NULL;
82+
83+
return of;
84+
}
85+
86+
static void kernfs_put_active_of(struct kernfs_open_file *of)
87+
{
88+
return kernfs_put_active(of->kn);
89+
}
90+
7391
/**
7492
* kernfs_deref_open_node_locked - Get kernfs_open_node corresponding to @kn
7593
*
@@ -139,7 +157,7 @@ static void kernfs_seq_stop_active(struct seq_file *sf, void *v)
139157

140158
if (ops->seq_stop)
141159
ops->seq_stop(sf, v);
142-
kernfs_put_active(of->kn);
160+
kernfs_put_active_of(of);
143161
}
144162

145163
static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
@@ -152,7 +170,7 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
152170
* the ops aren't called concurrently for the same open file.
153171
*/
154172
mutex_lock(&of->mutex);
155-
if (!kernfs_get_active(of->kn))
173+
if (!kernfs_get_active_of(of))
156174
return ERR_PTR(-ENODEV);
157175

158176
ops = kernfs_ops(of->kn);
@@ -238,7 +256,7 @@ static ssize_t kernfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
238256
* the ops aren't called concurrently for the same open file.
239257
*/
240258
mutex_lock(&of->mutex);
241-
if (!kernfs_get_active(of->kn)) {
259+
if (!kernfs_get_active_of(of)) {
242260
len = -ENODEV;
243261
mutex_unlock(&of->mutex);
244262
goto out_free;
@@ -252,7 +270,7 @@ static ssize_t kernfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
252270
else
253271
len = -EINVAL;
254272

255-
kernfs_put_active(of->kn);
273+
kernfs_put_active_of(of);
256274
mutex_unlock(&of->mutex);
257275

258276
if (len < 0)
@@ -323,7 +341,7 @@ static ssize_t kernfs_fop_write_iter(struct kiocb *iocb, struct iov_iter *iter)
323341
* the ops aren't called concurrently for the same open file.
324342
*/
325343
mutex_lock(&of->mutex);
326-
if (!kernfs_get_active(of->kn)) {
344+
if (!kernfs_get_active_of(of)) {
327345
mutex_unlock(&of->mutex);
328346
len = -ENODEV;
329347
goto out_free;
@@ -335,7 +353,7 @@ static ssize_t kernfs_fop_write_iter(struct kiocb *iocb, struct iov_iter *iter)
335353
else
336354
len = -EINVAL;
337355

338-
kernfs_put_active(of->kn);
356+
kernfs_put_active_of(of);
339357
mutex_unlock(&of->mutex);
340358

341359
if (len > 0)
@@ -357,13 +375,13 @@ static void kernfs_vma_open(struct vm_area_struct *vma)
357375
if (!of->vm_ops)
358376
return;
359377

360-
if (!kernfs_get_active(of->kn))
378+
if (!kernfs_get_active_of(of))
361379
return;
362380

363381
if (of->vm_ops->open)
364382
of->vm_ops->open(vma);
365383

366-
kernfs_put_active(of->kn);
384+
kernfs_put_active_of(of);
367385
}
368386

369387
static vm_fault_t kernfs_vma_fault(struct vm_fault *vmf)
@@ -375,14 +393,14 @@ static vm_fault_t kernfs_vma_fault(struct vm_fault *vmf)
375393
if (!of->vm_ops)
376394
return VM_FAULT_SIGBUS;
377395

378-
if (!kernfs_get_active(of->kn))
396+
if (!kernfs_get_active_of(of))
379397
return VM_FAULT_SIGBUS;
380398

381399
ret = VM_FAULT_SIGBUS;
382400
if (of->vm_ops->fault)
383401
ret = of->vm_ops->fault(vmf);
384402

385-
kernfs_put_active(of->kn);
403+
kernfs_put_active_of(of);
386404
return ret;
387405
}
388406

@@ -395,7 +413,7 @@ static vm_fault_t kernfs_vma_page_mkwrite(struct vm_fault *vmf)
395413
if (!of->vm_ops)
396414
return VM_FAULT_SIGBUS;
397415

398-
if (!kernfs_get_active(of->kn))
416+
if (!kernfs_get_active_of(of))
399417
return VM_FAULT_SIGBUS;
400418

401419
ret = 0;
@@ -404,7 +422,7 @@ static vm_fault_t kernfs_vma_page_mkwrite(struct vm_fault *vmf)
404422
else
405423
file_update_time(file);
406424

407-
kernfs_put_active(of->kn);
425+
kernfs_put_active_of(of);
408426
return ret;
409427
}
410428

@@ -418,14 +436,14 @@ static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
418436
if (!of->vm_ops)
419437
return -EINVAL;
420438

421-
if (!kernfs_get_active(of->kn))
439+
if (!kernfs_get_active_of(of))
422440
return -EINVAL;
423441

424442
ret = -EINVAL;
425443
if (of->vm_ops->access)
426444
ret = of->vm_ops->access(vma, addr, buf, len, write);
427445

428-
kernfs_put_active(of->kn);
446+
kernfs_put_active_of(of);
429447
return ret;
430448
}
431449

@@ -455,7 +473,7 @@ static int kernfs_fop_mmap(struct file *file, struct vm_area_struct *vma)
455473
mutex_lock(&of->mutex);
456474

457475
rc = -ENODEV;
458-
if (!kernfs_get_active(of->kn))
476+
if (!kernfs_get_active_of(of))
459477
goto out_unlock;
460478

461479
ops = kernfs_ops(of->kn);
@@ -490,7 +508,7 @@ static int kernfs_fop_mmap(struct file *file, struct vm_area_struct *vma)
490508
}
491509
vma->vm_ops = &kernfs_vm_ops;
492510
out_put:
493-
kernfs_put_active(of->kn);
511+
kernfs_put_active_of(of);
494512
out_unlock:
495513
mutex_unlock(&of->mutex);
496514

@@ -852,15 +870,15 @@ static __poll_t kernfs_fop_poll(struct file *filp, poll_table *wait)
852870
struct kernfs_node *kn = kernfs_dentry_node(filp->f_path.dentry);
853871
__poll_t ret;
854872

855-
if (!kernfs_get_active(kn))
873+
if (!kernfs_get_active_of(of))
856874
return DEFAULT_POLLMASK|EPOLLERR|EPOLLPRI;
857875

858876
if (kn->attr.ops->poll)
859877
ret = kn->attr.ops->poll(of, wait);
860878
else
861879
ret = kernfs_generic_poll(of, wait);
862880

863-
kernfs_put_active(kn);
881+
kernfs_put_active_of(of);
864882
return ret;
865883
}
866884

@@ -875,7 +893,7 @@ static loff_t kernfs_fop_llseek(struct file *file, loff_t offset, int whence)
875893
* the ops aren't called concurrently for the same open file.
876894
*/
877895
mutex_lock(&of->mutex);
878-
if (!kernfs_get_active(of->kn)) {
896+
if (!kernfs_get_active_of(of)) {
879897
mutex_unlock(&of->mutex);
880898
return -ENODEV;
881899
}
@@ -886,7 +904,7 @@ static loff_t kernfs_fop_llseek(struct file *file, loff_t offset, int whence)
886904
else
887905
ret = generic_file_llseek(file, offset, whence);
888906

889-
kernfs_put_active(of->kn);
907+
kernfs_put_active_of(of);
890908
mutex_unlock(&of->mutex);
891909
return ret;
892910
}

rust/kernel/device.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ pub mod property;
138138
/// }
139139
/// ```
140140
///
141-
/// An example for a class device implementation is [`drm::Device`].
141+
/// An example for a class device implementation is
142+
#[cfg_attr(CONFIG_DRM = "y", doc = "[`drm::Device`](kernel::drm::Device).")]
143+
#[cfg_attr(not(CONFIG_DRM = "y"), doc = "`drm::Device`.")]
142144
///
143145
/// # Invariants
144146
///
@@ -151,7 +153,6 @@ pub mod property;
151153
/// dropped from any thread.
152154
///
153155
/// [`AlwaysRefCounted`]: kernel::types::AlwaysRefCounted
154-
/// [`drm::Device`]: kernel::drm::Device
155156
/// [`impl_device_context_deref`]: kernel::impl_device_context_deref
156157
/// [`pci::Device`]: kernel::pci::Device
157158
/// [`platform::Device`]: kernel::platform::Device

0 commit comments

Comments
 (0)