Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

posix-clock: Store file pointer in struct posix_clock_context

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>

authored by

Wojtek Wasko and committed by
David S. Miller
e859d375 f252f23a

+6 -1
+5 -1
include/linux/posix-clock.h
··· 95 95 * struct posix_clock_context - represents clock file operations context 96 96 * 97 97 * @clk: Pointer to the clock 98 + * @fp: Pointer to the file used to open the clock 98 99 * @private_clkdata: Pointer to user data 99 100 * 100 101 * Drivers should use struct posix_clock_context during specific character 101 - * device file operation methods to access the posix clock. 102 + * device file operation methods to access the posix clock. In particular, 103 + * the file pointer can be used to verify correct access mode for ioctl() 104 + * calls. 102 105 * 103 106 * Drivers can store a private data structure during the open operation 104 107 * if they have specific information that is required in other file ··· 109 106 */ 110 107 struct posix_clock_context { 111 108 struct posix_clock *clk; 109 + struct file *fp; 112 110 void *private_clkdata; 113 111 }; 114 112
+1
kernel/time/posix-clock.c
··· 129 129 goto out; 130 130 } 131 131 pccontext->clk = clk; 132 + pccontext->fp = fp; 132 133 if (clk->ops.open) { 133 134 err = clk->ops.open(pccontext, fp->f_mode); 134 135 if (err) {