From: Jason Andryuk <jandryuk@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: "Eric W . Biederman" <ebiederm@xmission.com>,
Cyrill Gorcunov <gorcunov@gmail.com>,
Jason Andryuk <jandryuk@gmail.com>
Subject: [PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage
Date: Thu, 3 Feb 2022 08:31:34 -0500 [thread overview]
Message-ID: <20220203133134.6949-1-jandryuk@gmail.com> (raw)
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@gmail.com>
---
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
next reply other threads:[~2022-02-03 13:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 13:31 Jason Andryuk [this message]
2022-02-03 13:58 ` [PATCH v2] kcmp: Comment get_file_raw_ptr() RCU usage Cyrill Gorcunov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220203133134.6949-1-jandryuk@gmail.com \
--to=jandryuk@gmail.com \
--cc=ebiederm@xmission.com \
--cc=gorcunov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.