[PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage

From: Jason Andryuk
Date: Thu Feb 03 2022 - 08:31:59 EST


This usage of RCU appears wrong since the pointer is passed outside the
RCU region. However, it is only used as a number and not dereferenced,
so it is okay. Leave a comment for the next reader.

Without a reference, these comparisons are racy, but even with their use
inside an RCU region, the result could go stale.

Signed-off-by: Jason Andryuk <jandryuk@xxxxxxxxx>
---
v2:
Rephrase comment and tweak commit message. (Cyrill)

kernel/kcmp.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/kcmp.c b/kernel/kcmp.c
index 5353edfad8e1..04874c7ac0ab 100644
--- a/kernel/kcmp.c
+++ b/kernel/kcmp.c
@@ -63,6 +63,11 @@ get_file_raw_ptr(struct task_struct *task, unsigned int idx)
{
struct file *file;

+ /*
+ * Fetch file pointers inside RCU read-lock section, but
+ * skip additional locking for speed. The pointer values
+ * will be used as integers and must not be dereferenced.
+ */
rcu_read_lock();
file = task_lookup_fd_rcu(task, idx);
rcu_read_unlock();
--
2.34.1