]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
posix-clock: Store file pointer in struct posix_clock_context
authorWojtek Wasko <wwasko@nvidia.com>
Mon, 3 Mar 2025 16:13:43 +0000 (18:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 30 Jan 2026 09:27:30 +0000 (10:27 +0100)
[ Upstream commit e859d375d1694488015e6804bfeea527a0b25b9f ]

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

Character device operations (open, read, poll, ioctl) do not implement a
generic permission control and the dynamic 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 dynamic clock callbacks
can access it.

Acked-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Wojtek Wasko <wwasko@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/posix-clock.h
kernel/time/posix-clock.c

index ef8619f489203eeb369ae580fc4d4b2439c94ae9..a500d3160fe8c8a7334bca05c1059506b40bf78f 100644 (file)
@@ -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 to open 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 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;
 };
 
index a6487a9d608533052876d77df246e478e8c7955b..b130bb56cc4e03d62dc697d2e6e9bd5d5946580d 100644 (file)
@@ -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) {