netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wojtek Wasko <wwasko@nvidia.com>
To: netdev@vger.kernel.org
Cc: richardcochran@gmail.com, vadim.fedorenko@linux.dev,
	kuba@kernel.org, horms@kernel.org
Subject: [PATCH net-next v2 1/3] posix clocks: Store file pointer in clock context
Date: Tue, 11 Feb 2025 17:09:11 +0200	[thread overview]
Message-ID: <20250211150913.772545-2-wwasko@nvidia.com> (raw)
In-Reply-To: <20250211150913.772545-1-wwasko@nvidia.com>

Dynamic clocks (e.g. PTP clocks) need access to the permissions with
which the clock was opened to enforce proper access control.

Native POSIX clocks have access to this information via
posix_clock_desc. However, it is not accessible from the implementation
of dynamic clocks.

Add struct file* to POSIX clock context for access from dynamic clocks.

Signed-off-by: Wojtek Wasko <wwasko@nvidia.com>
---
 include/linux/posix-clock.h | 6 +++++-
 kernel/time/posix-clock.c   | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/linux/posix-clock.h b/include/linux/posix-clock.h
index ef8619f48920..40fa204baafc 100644
--- a/include/linux/posix-clock.h
+++ b/include/linux/posix-clock.h
@@ -95,10 +95,13 @@ struct posix_clock {
  * struct posix_clock_context - represents clock file operations context
  *
  * @clk:              Pointer to the clock
+ * @fp:               Pointer to the file used for opening the clock
  * @private_clkdata:  Pointer to user data
  *
  * Drivers should use struct posix_clock_context during specific character
- * device file operation methods to access the posix clock.
+ * device file operation methods to access the posix clock. In particular,
+ * the file pointer can be used to verify correct access mode for custom
+ * ioctl calls.
  *
  * Drivers can store a private data structure during the open operation
  * if they have specific information that is required in other file
@@ -106,6 +109,7 @@ struct posix_clock {
  */
 struct posix_clock_context {
 	struct posix_clock *clk;
+	struct file *fp;
 	void *private_clkdata;
 };
 
diff --git a/kernel/time/posix-clock.c b/kernel/time/posix-clock.c
index 1af0bb2cc45c..4e114e34a6e0 100644
--- a/kernel/time/posix-clock.c
+++ b/kernel/time/posix-clock.c
@@ -129,6 +129,7 @@ static int posix_clock_open(struct inode *inode, struct file *fp)
 		goto out;
 	}
 	pccontext->clk = clk;
+	pccontext->fp = fp;
 	if (clk->ops.open) {
 		err = clk->ops.open(pccontext, fp->f_mode);
 		if (err) {
-- 
2.39.3


  reply	other threads:[~2025-02-11 15:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-11 15:09 [PATCH net-next v2 0/3] Permission checks for dynamic POSIX clocks Wojtek Wasko
2025-02-11 15:09 ` Wojtek Wasko [this message]
2025-02-13 11:37   ` [PATCH net-next v2 1/3] posix clocks: Store file pointer in clock context Paolo Abeni
2025-02-13 22:17     ` Thomas Gleixner
2025-02-14 11:14       ` Wojtek Wasko
2025-02-11 15:09 ` [PATCH net-next v2 2/3] ptp: Add file permission checks on PHCs Wojtek Wasko
2025-02-11 15:09 ` [PATCH net-next v2 3/3] testptp: Add option to open PHC in readonly mode Wojtek Wasko
2025-02-11 16:51 ` [PATCH net-next v2 0/3] Permission checks for dynamic POSIX clocks Richard Cochran
2025-02-11 17:07 ` Vadim Fedorenko

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=20250211150913.772545-2-wwasko@nvidia.com \
    --to=wwasko@nvidia.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).