diff mbox series

[net-next,v2,1/3] posix clocks: Store file pointer in clock context

Message ID 20250211150913.772545-2-wwasko@nvidia.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Permission checks for dynamic POSIX clocks | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers fail 3 maintainers not CCed: tglx@linutronix.de frederic@kernel.org anna-maria@linutronix.de
netdev/build_clang success Errors and warnings before: 13 this patch: 13
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 28 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-12--06-00 (tests: 889)

Commit Message

Wojtek Wasko Feb. 11, 2025, 3:09 p.m. UTC
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(-)

Comments

Paolo Abeni Feb. 13, 2025, 11:37 a.m. UTC | #1
Posix clock maintainers have not being CC-ed, adding them.

The whole series is available at:

https://lore.kernel.org/all/20250211150913.772545-1-wwasko@nvidia.com/

On 2/11/25 4:09 PM, Wojtek Wasko wrote:
> 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) {
Thomas Gleixner Feb. 13, 2025, 10:17 p.m. UTC | #2
On Thu, Feb 13 2025 at 12:37, Paolo Abeni wrote:
> Posix clock maintainers have not being CC-ed, adding them.

Tx!

> $Subject: posix clocks: Store file pointer in clock context

s/posix_clocks:/posix-clock:/

s/clock context/struct posix_clock_context/

>> 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.

What is a native posix clock? posix_clock_desc is used in the context of
dynamic posix clocks, no?

I assume this wants to say:

 "The file descriptor based sys_clock_*() operations of dynamic posix
  clocks have access to the file pointer and implement permission checks
  in the generic code before invoking the relevant PTP clock callback.

  The character device operations (open, read, poll, ioctl) do not have
  a generic permission control and the PTP clock callbacks have no
  access to the file pointer to implement them.

  Extend struct posix_clock_context with a struct file pointer and
  initialize it in posix_clock_open(), so that all PTP clock callbacks
  can access it.

Or something like that, right?
 
>> @@ -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.

s/custom ioctl calls/ioctl() calls/

Other than that this looks sane.

Thanks,

        tglx
Wojtek Wasko Feb. 14, 2025, 11:14 a.m. UTC | #3
On Thu, Feb 13 2025 at 12:37, Paolo Abeni wrote:
> Posix clock maintainers have not being CC-ed, adding them.
Thank you! Initially this patch was fully contained in the ptp subsystem which is why I missed that.

On Thu, Feb 13 2025 at 23:17, Thomas Gleixner wrote:
> Other than that this looks sane.
I'll wait a day to see if there's any feedback from other posix-clock maintainers and post a v3 with revised wording.

Thanks,
Wojtek
diff mbox series

Patch

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) {