proc: move procfs to what kernfs does
Subsystems (78)
Christian Brauner
maintainerPATCH RESEND v2 6/23 powerpc/rtas: let procfs copy out reads
In reply to Christian BraunerImplement ->proc_read_buf() for the error log and the flash files so procfs copies what is read to userspace after it unpinned the entry.
The error log hands out a record the way it did before, the record is consumed before it reaches userspace. A reader that passes a NULL buffer now loses a record like one that passed a bad buffer always did, instead of getting -EINVAL. A blocking read still waits for a record with the entry pinned, as it did under use_pde() before; the entry is never removed, so nothing waits for it. The files can be spliced now, like every entry that is read through ->read_iter(). Note that a sendfile() from the error log into a target that fails or takes less than was read drops the records in between, splice_direct_to_actor() rewinds any seekable file like that and the error log doesn't hand a record out twice.
--- arch/powerpc/kernel/rtas_flash.c | 24 ++++++++++++------------ arch/powerpc/kernel/rtasd.c | 19 +++++-------------- 2 files changed, 17 insertions(+), 26 deletions(-)
arch/powerpc/kernel/rtas_flash.c +12 -12
@@ -269,7 +269,7 @@ static size_t get_flash_status_msg(int status, char *buf) }/* Reading the proc file will show status (not the firmware contents) */ -static ssize_t rtas_flash_read_msg (struct file *file,char __user *buf, +static ssize_t rtas_flash_read_msg (struct file *file,char *buf,size_t count,loff_t *ppos) {struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
@@ -283,10 +283,10 @@ static ssize_t rtas_flash_read_msg(struct file *file, char __user *buf,/* Read as text message */ len =get_flash_status_msg (status, msg); -return simple_read_from_buffer (buf, count, ppos, msg, len); +return memory_read_from_buffer (buf, count, ppos, msg, len); } -static ssize_t rtas_flash_read_num (struct file *file,char __user *buf, +static ssize_t rtas_flash_read_num (struct file *file,char *buf,size_t count,loff_t *ppos) {struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
@@ -299,7 +299,7 @@ static ssize_t rtas_flash_read_num(struct file *file, char __user *buf,/* Read as number */ sprintf (msg,"%d\n" , status); -return simple_read_from_buffer (buf, count, ppos, msg,strlen (msg)); +return memory_read_from_buffer (buf, count, ppos, msg,strlen (msg)); }/* We could be much more efficient here. But to keep this function
@@ -370,7 +370,7 @@ static void manage_flash(struct rtas_manage_flash_t *args_buf, unsigned int op) args_buf->status = rc; } -static ssize_t manage_flash_read (struct file *file,char __user *buf, +static ssize_t manage_flash_read (struct file *file,char *buf,size_t count,loff_t *ppos) {struct rtas_manage_flash_t *const args_buf = &rtas_manage_flash_data;
@@ -382,7 +382,7 @@ static ssize_t manage_flash_read(struct file *file, char __user *buf,mutex_unlock (&rtas_manage_flash_mutex); msglen =sprintf (msg,"%d\n" , status); -return simple_read_from_buffer (buf, count, ppos, msg, msglen); +return memory_read_from_buffer (buf, count, ppos, msg, msglen); } static ssize_t manage_flash_write(struct file *file, char *buf,
@@ -450,7 +450,7 @@ static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,return n; } -static ssize_t validate_flash_read (struct file *file,char __user *buf, +static ssize_t validate_flash_read (struct file *file,char *buf,size_t count,loff_t *ppos) { struct rtas_validate_flash_t *const args_buf =
@@ -462,7 +462,7 @@ static ssize_t validate_flash_read(struct file *file, char __user *buf, msglen =get_validate_flash_msg (args_buf, msg,VALIDATE_MSG_LEN );mutex_unlock (&rtas_validate_flash_mutex); -return simple_read_from_buffer (buf, count, ppos, msg, msglen); +return memory_read_from_buffer (buf, count, ppos, msg, msglen); } static ssize_t validate_flash_write(struct file *file, char *buf,
@@ -623,7 +623,7 @@ static const struct rtas_flash_file rtas_flash_files[] = { .handle = RTAS_FN_IBM_UPDATE_FLASH_64_AND_REBOOT, .status = &rtas_update_flash_data.status, .ops.proc_flags = PROC_ENTRY_SHORT_WRITES, - .ops.proc_read = rtas_flash_read_msg, + .ops.proc_read_buf = rtas_flash_read_msg, .ops.proc_write_buf = rtas_flash_write, .ops.proc_write_size = RTAS_BLK_SIZE, .ops.proc_release = rtas_flash_release,
@@ -634,7 +634,7 @@ static const struct rtas_flash_file rtas_flash_files[] = { .handle = RTAS_FN_IBM_UPDATE_FLASH_64_AND_REBOOT, .status = &rtas_update_flash_data.status, .ops.proc_flags = PROC_ENTRY_SHORT_WRITES, - .ops.proc_read = rtas_flash_read_num, + .ops.proc_read_buf = rtas_flash_read_num, .ops.proc_write_buf = rtas_flash_write, .ops.proc_write_size = RTAS_BLK_SIZE, .ops.proc_release = rtas_flash_release,
@@ -645,7 +645,7 @@ static const struct rtas_flash_file rtas_flash_files[] = { .handle = RTAS_FN_IBM_VALIDATE_FLASH_IMAGE, .status = &rtas_validate_flash_data.status, .ops.proc_flags = PROC_ENTRY_SHORT_WRITES, - .ops.proc_read = validate_flash_read, + .ops.proc_read_buf = validate_flash_read, .ops.proc_write_buf = validate_flash_write, .ops.proc_write_size = VALIDATE_BUF_SIZE, .ops.proc_release = validate_flash_release,
@@ -655,7 +655,7 @@ static const struct rtas_flash_file rtas_flash_files[] = { .filename = "powerpc/rtas/" MANAGE_FLASH_NAME, .handle = RTAS_FN_IBM_MANAGE_FLASH_IMAGE, .status = &rtas_manage_flash_data.status, - .ops.proc_read = manage_flash_read, + .ops.proc_read_buf = manage_flash_read, .ops.proc_write_buf = manage_flash_write, .ops.proc_lseek = default_llseek, }
arch/powerpc/kernel/rtasd.c +5 -14
@@ -291,26 +291,18 @@ static int rtas_log_release(struct inode * inode, struct file * file)* know that we can safely clear the events in NVRAM. * Next we'll sit and wait for something else to log. */ -static ssize_t rtas_log_read (struct file * file,char __user * buf, +static ssize_t rtas_log_read (struct file * file,char * buf,size_t count,loff_t *ppos) {int error; -char *tmp;unsigned long s;unsigned long offset; -if (!buf || count < rtas_error_log_buffer_max) +if (count < rtas_error_log_buffer_max)return -EINVAL ; count = rtas_error_log_buffer_max; -if (!access_ok (buf, count)) -return -EFAULT ; - - tmp =kmalloc (count,GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; -spin_lock_irqsave (&rtasd_log_lock, s);/* if it's 0, then we know we got the last one (the one in NVRAM) */
@@ -338,15 +330,14 @@ static ssize_t rtas_log_read(struct file * file, char __user * buf, } offset = rtas_error_log_buffer_max * (rtas_log_start &LOG_NUMBER_MASK ); -memcpy (tmp, &rtas_log_buf[offset], count); +memcpy (buf, &rtas_log_buf[offset], count); rtas_log_start +=1 ; rtas_log_size -=1 ;spin_unlock_irqrestore (&rtasd_log_lock, s); - error =copy_to_user (buf, tmp, count) ? -EFAULT : count; + error = count; out: -kfree (tmp);return error; }
@@ -359,7 +350,7 @@ static __poll_t rtas_log_poll(struct file *file, poll_table * wait) }static const struct proc_ops rtas_log_proc_ops = { - .proc_read = rtas_log_read, + .proc_read_buf = rtas_log_read, .proc_poll = rtas_log_poll, .proc_open = rtas_log_open, .proc_release = rtas_log_release,
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 7/23 powerpc/rtasd: let procfs own the wait queue of the rtas error log
In reply to Christian Braunerrtas_log_poll() sleeps the poller on rtas_log_wait, which the blocking read sleeps on as well. procfs owns the queue poll() uses now, so leave the poll_wait() to it and wake its pollers along with the readers.
--- arch/powerpc/kernel/rtasd.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
arch/powerpc/kernel/rtasd.c +5 -6
@@ -33,6 +33,7 @@static DEFINE_SPINLOCK (rtasd_log_lock);static DECLARE_WAIT_QUEUE_HEAD (rtas_log_wait); +static struct proc_dir_entry *rtas_log_entry;static char *rtas_log_buf;static unsigned long rtas_log_start;
@@ -259,6 +260,7 @@ void pSeries_log_error(char *buf, unsigned int err_type, int fatal)WARN_ON_ONCE (!irqs_disabled ());/* @@@ DEBUG @@@ */ spin_unlock_irqrestore (&rtasd_log_lock, s);wake_up_interruptible (&rtas_log_wait); +proc_poll_notify (rtas_log_entry);break ;case ERR_TYPE_KERNEL_PANIC :default :
@@ -343,7 +345,6 @@ out:static __poll_t rtas_log_poll (struct file *file,poll_table * wait) { -poll_wait (file, &rtas_log_wait, wait);if (rtas_log_size)return EPOLLIN |EPOLLRDNORM ;return 0 ;
@@ -529,17 +530,15 @@ arch_initcall(rtas_event_scan_init);static int __init rtas_init (void ) { -struct proc_dir_entry *entry; -if (!machine_is (pseries) && !machine_is (chrp))return 0 ;if (!rtas_log_buf)return -ENODEV ; - entry =proc_create ("powerpc/rtas/error_log" ,0400 ,NULL , - &rtas_log_proc_ops); -if (!entry) + rtas_log_entry =proc_create ("powerpc/rtas/error_log" ,0400 ,NULL , + &rtas_log_proc_ops); +if (!rtas_log_entry)printk (KERN_ERR "Failed to create error_log proc entry\n" );return 0 ;
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 8/23 powerpc/pseries: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for lparcfg, ofdt and the vcpudispatch files so procfs copies in what is written before it pins the entry, and parse what was written from that copy. ofdt takes as much as memdup_user_nul() could copy before since device tree updates can be large.
--- arch/powerpc/platforms/pseries/lpar.c | 14 ++++++-------- arch/powerpc/platforms/pseries/lparcfg.c | 7 +++---- arch/powerpc/platforms/pseries/reconfig.c | 22 ++++++++-------------- 3 files changed, 17 insertions(+), 26 deletions(-)
arch/powerpc/platforms/pseries/lpar.c +6 -8
@@ -498,7 +498,7 @@ static void dtl_worker_disable(unsigned long *time_limit)up_write (&dtl_access_lock); } -static ssize_t vcpudispatch_stats_write (struct file *file,const char __user *p, +static ssize_t vcpudispatch_stats_write (struct file *file,char *p,size_t count,loff_t *ppos) {unsigned long time_limit = jiffies +HZ ;
@@ -509,8 +509,7 @@ static ssize_t vcpudispatch_stats_write(struct file *file, const char __user *p,if (count >15 )return -EINVAL ; -if (copy_from_user (buf, p, count)) -return -EFAULT ; +memcpy (buf, p, count); buf[count] =0 ; rc =kstrtoint (buf,0 , &cmd);
@@ -586,11 +585,11 @@ static int vcpudispatch_stats_display(struct seq_file *p, void *v)static const struct proc_ops vcpudispatch_stats_proc_ops = { .proc_show = vcpudispatch_stats_display, - .proc_write = vcpudispatch_stats_write, + .proc_write_buf = vcpudispatch_stats_write, };static ssize_t vcpudispatch_stats_freq_write (struct file *file, -const char __user *p,size_t count,loff_t *ppos) +char *p,size_t count,loff_t *ppos) {int rc, freq;char buf[16 ];
@@ -598,8 +597,7 @@ static ssize_t vcpudispatch_stats_freq_write(struct file *file,if (count >15 )return -EINVAL ; -if (copy_from_user (buf, p, count)) -return -EFAULT ; +memcpy (buf, p, count); buf[count] =0 ; rc =kstrtoint (buf,0 , &freq);
@@ -622,7 +620,7 @@ static int vcpudispatch_stats_freq_display(struct seq_file *p, void *v)static const struct proc_ops vcpudispatch_stats_freq_proc_ops = { .proc_show = vcpudispatch_stats_freq_display, - .proc_write = vcpudispatch_stats_freq_write, + .proc_write_buf = vcpudispatch_stats_freq_write, };static int __init vcpudispatch_stats_procfs_init (void )
arch/powerpc/platforms/pseries/lparcfg.c +3 -4
@@ -687,7 +687,7 @@ static ssize_t update_mpp(u64 *entitlement, u8 *weight)* This function should be invoked only on systems with * FW_FEATURE_SPLPAR. */ -static ssize_t lparcfg_write (struct file *file,const char __user * buf, +static ssize_t lparcfg_write (struct file *file,char *buf,size_t count,loff_t * off) {char kbuf[64 ];
@@ -702,8 +702,7 @@ static ssize_t lparcfg_write(struct file *file, const char __user * buf,if (count ==0 || count >=sizeof (kbuf))return -EINVAL ; -if (copy_from_user (kbuf, buf, count)) -return -EFAULT ; +memcpy (kbuf, buf, count); kbuf[count] ='\0' ; tmp =strchr (kbuf,'=' );if (!tmp)
@@ -798,7 +797,7 @@ static int lparcfg_data(struct seq_file *m, void *v) }static const struct proc_ops lparcfg_proc_ops = { - .proc_write = lparcfg_write, + .proc_write_buf = lparcfg_write, .proc_show = lparcfg_data, };
arch/powerpc/platforms/pseries/reconfig.c +8 -14
@@ -349,7 +349,7 @@ static int do_update_property(char *buf, size_t bufsize)* ofdt_write - perform operations on the Open Firmware device tree * * @file: not used -* @buf: command and arguments +* @kbuf: command and arguments * @count: size of the command buffer * @off: not used *
@@ -357,26 +357,19 @@ static int do_update_property(char *buf, size_t bufsize)* whole nodes along with their properties. Operations on individual * properties are not implemented (yet). */ -static ssize_t ofdt_write (struct file *file,const char __user *buf,size_t count, +static ssize_t ofdt_write (struct file *file,char *kbuf,size_t count,loff_t *off) {int rv; -char *kbuf;char *tmp; rv =security_locked_down (LOCKDOWN_DEVICE_TREE );if (rv)return rv; - kbuf =memdup_user_nul (buf, count); -if (IS_ERR (kbuf)) -return PTR_ERR (kbuf); - tmp =strchr (kbuf,' ' ); -if (!tmp) { - rv = -EINVAL ; - goto out; - } +if (!tmp) +return -EINVAL ; *tmp ='\0' ; tmp++;
@@ -392,13 +385,14 @@ static ssize_t ofdt_write(struct file *file, const char __user *buf, size_t coun rv =do_update_property (tmp, count - (tmp - kbuf)); else rv = -EINVAL ; -out: -kfree (kbuf); +return rv ? rv : count; }static const struct proc_ops ofdt_proc_ops = { - .proc_write = ofdt_write, + .proc_write_buf = ofdt_write, +/* what memdup_user_nul() could copy in */ + .proc_write_size =KMALLOC_MAX_SIZE -1 , .proc_lseek = noop_llseek, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 9/23 powerpc/procfs: let procfs copy out reads of /proc/powerpc/systemcfg
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry.
--- arch/powerpc/kernel/proc_powerpc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kernel/proc_powerpc.c +3 -3
@@ -24,10 +24,10 @@ static loff_t page_map_seek(struct file *file, loff_t off, int whence)return fixed_size_llseek (file, off, whence,PAGE_SIZE ); } -static ssize_t page_map_read (struct file *file,char __user *buf,size_t nbytes, +static ssize_t page_map_read (struct file *file,char *buf,size_t nbytes,loff_t *ppos) { -return simple_read_from_buffer (buf, nbytes, ppos, +return memory_read_from_buffer (buf, nbytes, ppos,pde_data (file_inode (file)),PAGE_SIZE ); }
@@ -43,7 +43,7 @@ static int page_map_mmap( struct file *file, struct vm_area_struct *vma )static const struct proc_ops page_map_proc_ops = { .proc_lseek = page_map_seek, - .proc_read = page_map_read, + .proc_read_buf = page_map_read, .proc_mmap = page_map_mmap, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 10/23 sh: alignment: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to the alignment files before it pins the entry, and take the mode from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- arch/sh/mm/alignment.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/sh/mm/alignment.c +3 -4
@@ -133,14 +133,13 @@ static int alignment_proc_show(struct seq_file *m, void *v) }static ssize_t alignment_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {int *data =pde_data (file_inode (file));char mode;if (count >0 ) { -if (get_user (mode, buffer)) -return -EFAULT ; + mode = buffer[0 ];if (mode >='0' && mode <='5' ) *data = mode -'0' ; }
@@ -149,7 +148,7 @@ static ssize_t alignment_proc_write(struct file *file,static const struct proc_ops alignment_proc_ops = { .proc_show = alignment_proc_show, - .proc_write = alignment_proc_write, + .proc_write_buf = alignment_proc_write, };/*
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 11/23 sparc: led: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to /proc/led before it pins the entry, and parse the command from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- arch/sparc/kernel/led.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
arch/sparc/kernel/led.c +3 -9
@@ -60,18 +60,14 @@ static int led_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t led_proc_write (struct file *file,const char __user *buffer, +static ssize_t led_proc_write (struct file *file,char *buf,size_t count,loff_t *ppos) {size_t len = count; -char *buf =NULL ;if (count >LED_MAX_LENGTH ) count =LED_MAX_LENGTH ; - - buf =memdup_user_nul (buffer, count); -if (IS_ERR (buf)) -return PTR_ERR (buf); + buf[count] ='\0' ;/* work around \n when echo'ing into proc */ if (count >0 && buf[count -1 ] =='\n' )
@@ -96,14 +92,12 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer, auxio_set_led(AUXIO_LED_OFF); } -kfree (buf); -return len; }static const struct proc_ops led_proc_ops = { .proc_show = led_proc_show, - .proc_write = led_proc_write, + .proc_write_buf = led_proc_write, };#endif
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 12/23 um: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for the mconsole and exitcode files so procfs copies in what is written before it pins the entry. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
exitcode parses procfs' copy as is, so it no longer stops at the first six bytes of what is written.
--- arch/um/drivers/mconsole_kern.c | 11 ++--------- arch/um/kernel/exitcode.c | 14 ++++---------- 2 files changed, 6 insertions(+), 19 deletions(-)
arch/um/drivers/mconsole_kern.c +2 -9
@@ -769,21 +769,14 @@ static int __init mconsole_init(void)__initcall (mconsole_init);static ssize_t mconsole_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buf,size_t count,loff_t *pos) { -char *buf; - - buf =memdup_user_nul (buffer, count); -if (IS_ERR (buf)) -return PTR_ERR (buf); -mconsole_notify (notify_socket,MCONSOLE_USER_NOTIFY , buf, count); -kfree (buf);return count; }static const struct proc_ops mconsole_proc_ops = { - .proc_write = mconsole_proc_write, + .proc_write_buf = mconsole_proc_write, .proc_lseek = noop_llseek, };
arch/um/kernel/exitcode.c +4 -10
@@ -32,18 +32,12 @@ static int exitcode_proc_show(struct seq_file *m, void *v) }static ssize_t exitcode_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) { -char *end, buf[sizeof ("nnnnn\0" )]; -size_t size; +char *end;int tmp; - size =min (count,sizeof (buf) -1 ); -if (copy_from_user (buf, buffer, size)) -return -EFAULT ; - buf[size] ='\0' ; - - tmp =simple_strtol (buf, &end,0 ); + tmp =simple_strtol (buffer, &end,0 );if ((*end !='\0' ) && !isspace (*end))return -EINVAL ;
@@ -53,7 +47,7 @@ static ssize_t exitcode_proc_write(struct file *file,static const struct proc_ops exitcode_proc_ops = { .proc_show = exitcode_proc_show, - .proc_write = exitcode_proc_write, + .proc_write_buf = exitcode_proc_write, };static int make_proc_exitcode (void )
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 13/23 x86/mtrr: let procfs own the seq_file of /proc/mtrr
In reply to Christian BraunerDeclare the show function and let procfs open and free the seq_file. ->proc_open() only does the checks now and ->proc_release() only drops the MTRRs the file added.
--- arch/x86/kernel/cpu/mtrr/if.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +3 -4
@@ -349,7 +349,7 @@ static int mtrr_close(struct inode *ino, struct file *file)kfree (fcount);FILE_FCOUNT (file) =NULL ; } -return single_release (ino, file); +return 0 ; }static int mtrr_seq_show (struct seq_file *seq,void *offset)
@@ -391,13 +391,12 @@ static int mtrr_open(struct inode *inode, struct file *file)return -ENXIO ;if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -return single_open (file, mtrr_seq_show,NULL ); +return 0 ; }static const struct proc_ops mtrr_proc_ops = { + .proc_show = mtrr_seq_show, .proc_open = mtrr_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_write = mtrr_write, .proc_ioctl = mtrr_ioctl, #ifdef CONFIG_COMPAT
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 14/23 x86/mtrr: let procfs copy in writes to /proc/mtrr
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and parse the command from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- arch/x86/kernel/cpu/mtrr/if.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +4 -5
@@ -91,7 +91,7 @@ mtrr_file_del(unsigned long base, unsigned long size,* "base=%Lx size=%Lx type=%s" or "disable=%d" */ static ssize_t -mtrr_write (struct file *file,const char __user *buf,size_t len,loff_t * ppos) +mtrr_write (struct file *file,char *buf,size_t len,loff_t * ppos) {int i, err;unsigned long reg;
@@ -103,9 +103,8 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)memset (line,0 ,LINE_SIZE ); len =min_t (size_t, len,LINE_SIZE -1 ); - length =strncpy_from_user (line, buf, len); -if (length <0 ) -return length; + length =strnlen (buf, len); +memcpy (line, buf, length); ptr = line + length -1 ;if (length && *ptr =='\n' )
@@ -397,7 +396,7 @@ static int mtrr_open(struct inode *inode, struct file *file)static const struct proc_ops mtrr_proc_ops = { .proc_show = mtrr_seq_show, .proc_open = mtrr_open, - .proc_write = mtrr_write, + .proc_write_buf = mtrr_write, .proc_ioctl = mtrr_ioctl, #ifdef CONFIG_COMPAT .proc_compat_ioctl = mtrr_ioctl,
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 15/23 x86/mtrr: let procfs copy the ioctl arguments of /proc/mtrr
In reply to Christian BraunerImplement ->proc_ioctl_buf() so procfs copies the arguments in before it pins the entry and back out after unpinning it. The native and the 32-bit commands encode their arguments and share one table. mtrr_ioctl() reads and fills procfs' copy, also in the 32-bit layouts.
--- arch/x86/kernel/cpu/mtrr/if.c | 79 +++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 33 deletions(-)
arch/x86/kernel/cpu/mtrr/if.c +46 -33
@@ -149,7 +149,7 @@ mtrr_write(struct file *file, char *buf, size_t len, loff_t * ppos) }static long -mtrr_ioctl (struct file *file,unsigned int cmd,unsigned long __arg) +mtrr_ioctl (struct file *file,unsigned int cmd,void *arg) {int err =0 ;mtrr_type type;
@@ -157,7 +157,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)unsigned long size;struct mtrr_sentry sentry;struct mtrr_gentry gentry; -void __user *arg = (void __user *) __arg;memset (&gentry,0 ,sizeof (gentry));
@@ -170,13 +169,11 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)case MTRRIOC_SET_PAGE_ENTRY :case MTRRIOC_DEL_PAGE_ENTRY :case MTRRIOC_KILL_PAGE_ENTRY : -if (copy_from_user (&sentry, arg,sizeof (sentry))) -return -EFAULT ; +memcpy (&sentry, arg,sizeof (sentry));break ;case MTRRIOC_GET_ENTRY :case MTRRIOC_GET_PAGE_ENTRY : -if (copy_from_user (&gentry, arg,sizeof (gentry))) -return -EFAULT ; +memcpy (&gentry, arg,sizeof (gentry));break ;#ifdef CONFIG_COMPAT case MTRRIOC32_ADD_ENTRY :
@@ -187,27 +184,21 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)case MTRRIOC32_SET_PAGE_ENTRY :case MTRRIOC32_DEL_PAGE_ENTRY :case MTRRIOC32_KILL_PAGE_ENTRY : { -struct mtrr_sentry32 __user *s32; +struct mtrr_sentry32 *s32 = arg; - s32 = (struct mtrr_sentry32 __user *)__arg; - err =get_user (sentry.base, &s32->base); - err |=get_user (sentry.size, &s32->size); - err |=get_user (sentry.type, &s32->type); -if (err) -return err; + sentry.base = s32->base; + sentry.size = s32->size; + sentry.type = s32->type;break ; }case MTRRIOC32_GET_ENTRY :case MTRRIOC32_GET_PAGE_ENTRY : { -struct mtrr_gentry32 __user *g32; +struct mtrr_gentry32 *g32 = arg; - g32 = (struct mtrr_gentry32 __user *)__arg; - err =get_user (gentry.regnum, &g32->regnum); - err |=get_user (gentry.base, &g32->base); - err |=get_user (gentry.size, &g32->size); - err |=get_user (gentry.type, &g32->type); -if (err) -return err; + gentry.regnum = g32->regnum; + gentry.base = g32->base; + gentry.size = g32->size; + gentry.type = g32->type;break ; }#endif
@@ -312,19 +303,17 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)switch (cmd) {case MTRRIOC_GET_ENTRY :case MTRRIOC_GET_PAGE_ENTRY : -if (copy_to_user (arg, &gentry,sizeof (gentry))) - err = -EFAULT ; +memcpy (arg, &gentry,sizeof (gentry));break ;#ifdef CONFIG_COMPAT case MTRRIOC32_GET_ENTRY :case MTRRIOC32_GET_PAGE_ENTRY : { -struct mtrr_gentry32 __user *g32; +struct mtrr_gentry32 *g32 = arg; - g32 = (struct mtrr_gentry32 __user *)__arg; - err =put_user (gentry.base, &g32->base); - err |=put_user (gentry.size, &g32->size); - err |=put_user (gentry.regnum, &g32->regnum); - err |=put_user (gentry.type, &g32->type); + g32->base = gentry.base; + g32->size = gentry.size; + g32->regnum = gentry.regnum; + g32->type = gentry.type;break ; }#endif
@@ -393,14 +382,38 @@ static int mtrr_open(struct inode *inode, struct file *file)return 0 ; } +static const struct proc_ioctl_arg mtrr_ioctl_args[] = { +PROC_IOCTL_IOC (MTRRIOC_ADD_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_SET_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_DEL_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_GET_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_KILL_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_ADD_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_SET_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_DEL_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_GET_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC_KILL_PAGE_ENTRY ), +#ifdef CONFIG_COMPAT +PROC_IOCTL_IOC (MTRRIOC32_ADD_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_SET_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_DEL_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_GET_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_KILL_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_ADD_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_SET_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_DEL_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_GET_PAGE_ENTRY ), +PROC_IOCTL_IOC (MTRRIOC32_KILL_PAGE_ENTRY ), +#endif +}; +static const struct proc_ops mtrr_proc_ops = { .proc_show = mtrr_seq_show, .proc_open = mtrr_open, .proc_write_buf = mtrr_write, - .proc_ioctl = mtrr_ioctl, -#ifdef CONFIG_COMPAT - .proc_compat_ioctl = mtrr_ioctl, -#endif + .proc_ioctl_buf = mtrr_ioctl, + .proc_ioctl_args = mtrr_ioctl_args, + .proc_nr_ioctl_args =ARRAY_SIZE (mtrr_ioctl_args), .proc_release = mtrr_close, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 16/23 xtensa: simdisk: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to the simdisk files before it pins the entry, and take the file name from that copy. The files took up to PAGE_SIZE bytes and keep doing that through ->proc_write_size.
--- arch/xtensa/platforms/iss/simdisk.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
arch/xtensa/platforms/iss/simdisk.c +10 -16
@@ -241,7 +241,7 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,ssize_t len;char *temp; -/* a write sets at most a page, see proc_write_simdisk() */ +/* a write sets at most a page, see simdisk_proc_ops */ temp =kmalloc (PAGE_SIZE +2 ,GFP_KERNEL );if (!temp)return -ENOMEM ;
@@ -255,40 +255,34 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf,return len; } -static ssize_t proc_write_simdisk (struct file *file,const char __user *buf, +static ssize_t proc_write_simdisk (struct file *file,char *buf,size_t count,loff_t *ppos) { -char *tmp;struct simdisk *dev =pde_data (file_inode (file));int err; -if (count ==0 || count >PAGE_SIZE ) +if (count ==0 )return -EINVAL ; - tmp =memdup_user_nul (buf, count); -if (IS_ERR (tmp)) -return PTR_ERR (tmp); - err =simdisk_detach (dev);if (err !=0 ) - goto out_free; +return err; -if (count >0 && tmp[count -1 ] =='\n' ) - tmp[count -1 ] =0 ; +if (count >0 && buf[count -1 ] =='\n' ) + buf[count -1 ] =0 ; -if (tmp[0 ]) - err =simdisk_attach (dev, tmp); +if (buf[0 ]) + err =simdisk_attach (dev, buf);if (err ==0 ) err = count; -out_free: -kfree (tmp);return err; }static const struct proc_ops simdisk_proc_ops = { .proc_read = proc_read_simdisk, - .proc_write = proc_write_simdisk, + .proc_write_buf = proc_write_simdisk, + .proc_write_size =PAGE_SIZE , .proc_lseek = default_llseek, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 17/23 xtensa: simdisk: let procfs copy out reads
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry.
--- arch/xtensa/platforms/iss/simdisk.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/xtensa/platforms/iss/simdisk.c +3 -3
@@ -234,7 +234,7 @@ static int simdisk_detach(struct simdisk *dev)return err; } -static ssize_t proc_read_simdisk (struct file *file,char __user *buf, +static ssize_t proc_read_simdisk (struct file *file,char *buf,size_t size,loff_t *ppos) {struct simdisk *dev =pde_data (file_inode (file));
@@ -250,7 +250,7 @@ static ssize_t proc_read_simdisk(struct file *file, char __user *buf, len =scnprintf (temp,PAGE_SIZE +2 ,"%s\n" , dev->filename ?:"" );spin_unlock (&dev->lock); - len =simple_read_from_buffer (buf, size, ppos, temp, len); + len =memory_read_from_buffer (buf, size, ppos, temp, len);kfree (temp);return len; }
@@ -280,7 +280,7 @@ static ssize_t proc_write_simdisk(struct file *file, char *buf, }static const struct proc_ops simdisk_proc_ops = { - .proc_read = proc_read_simdisk, + .proc_read_buf = proc_read_simdisk, .proc_write_buf = proc_write_simdisk, .proc_write_size =PAGE_SIZE , .proc_lseek = default_llseek,
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 18/23 ACPI: proc: let procfs copy in writes to /proc/acpi/wakeup
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and take the device name from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- drivers/acpi/proc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/acpi/proc.c +3 -4
@@ -86,7 +86,7 @@ static void physical_device_enable_wakeup(struct acpi_device *adev)static ssize_t acpi_system_write_wakeup_device (struct file *file, -const char __user * buffer, +char *buffer,size_t count,loff_t * ppos) {struct acpi_device *dev, *tmp;
@@ -96,8 +96,7 @@ acpi_system_write_wakeup_device(struct file *file,if (count >4 ) count =4 ; -if (copy_from_user (strbuf, buffer, count)) -return -EFAULT ; +memcpy (strbuf, buffer, count); strbuf[count] ='\0' ;sscanf (strbuf,"%s" , str);
@@ -123,7 +122,7 @@ acpi_system_write_wakeup_device(struct file *file,static const struct proc_ops acpi_system_wakeup_device_proc_ops = { .proc_show = acpi_system_wakeup_device_seq_show, - .proc_write = acpi_system_write_wakeup_device, + .proc_write_buf = acpi_system_write_wakeup_device, };void __init acpi_sleep_proc_init (void )
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 19/23 macintosh/via-pmu: let procfs copy in writes to the options file
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and parse the option from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- drivers/macintosh/via-pmu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/macintosh/via-pmu.c +3 -4
@@ -913,7 +913,7 @@ static int pmu_options_proc_show(struct seq_file *m, void *v) }static ssize_t pmu_options_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {char tmp[33 ];char *label, *val;
@@ -923,8 +923,7 @@ static ssize_t pmu_options_proc_write(struct file *file,return -EINVAL ;if (count >32 ) count =32 ; -if (copy_from_user (tmp, buffer, count)) -return -EFAULT ; +memcpy (tmp, buffer, count); tmp[count] =0 ; label = tmp;
@@ -958,7 +957,7 @@ static ssize_t pmu_options_proc_write(struct file *file,static const struct proc_ops pmu_options_proc_ops = { .proc_show = pmu_options_proc_show, - .proc_write = pmu_options_proc_write, + .proc_write_buf = pmu_options_proc_write, };#endif
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 20/23 platform/x86: thinkpad_acpi: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to /proc/acpi/ibm/* before it pins the entry, and hand that copy to ->write(). procfs already rejects writes larger than PAGE_SIZE - 1 bytes.
--- drivers/platform/x86/lenovo/thinkpad_acpi.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +3 -9
@@ -882,7 +882,7 @@ static int dispatch_proc_show(struct seq_file *m, void *v) }static ssize_t dispatch_proc_write (struct file *file, -const char __user *userbuf, +char *buf,size_t count,loff_t *pos) {struct ibm_struct *ibm =pde_data (file_inode (file));
@@ -890,14 +890,8 @@ static ssize_t dispatch_proc_write(struct file *file,if (!ibm || !ibm->write)return -EINVAL ; -if (count >PAGE_SIZE -1 ) -return -EINVAL ; - - char *kernbuf __free(kfree) = memdup_user_nul(userbuf, count); -if (IS_ERR (kernbuf)) -return PTR_ERR (kernbuf); - ret = ibm->write (kernbuf); + ret = ibm->write (buf);if (ret)return ret;
@@ -906,7 +900,7 @@ static ssize_t dispatch_proc_write(struct file *file,static const struct proc_ops dispatch_proc_ops = { .proc_show = dispatch_proc_show, - .proc_write = dispatch_proc_write, + .proc_write_buf = dispatch_proc_write, };/****************************************************************************
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 21/23 platform/x86: toshiba_acpi: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for the files in /proc/acpi/toshiba so procfs copies in what is written before it pins the entry, and parse what was written from that copy. Commands longer than PAGE_SIZE - 1 bytes are rejected now.
--- drivers/platform/x86/toshiba_acpi.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-)
drivers/platform/x86/toshiba_acpi.c +12 -24
@@ -1478,7 +1478,7 @@ static int set_lcd_status(struct backlight_device *bd)return set_lcd_brightness (dev, bd->props.brightness); } -static ssize_t lcd_proc_write (struct file *file,const char __user *buf, +static ssize_t lcd_proc_write (struct file *file,char *buf,size_t count,loff_t *pos) {struct toshiba_acpi_dev *dev =pde_data (file_inode (file));
@@ -1488,8 +1488,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,int value; len =min (count,sizeof (cmd) -1 ); -if (copy_from_user (cmd, buf, len)) -return -EFAULT ; +memcpy (cmd, buf, len); cmd[len] ='\0' ; levels = dev->backlight_dev->props.max_brightness +1 ;
@@ -1505,7 +1504,7 @@ static ssize_t lcd_proc_write(struct file *file, const char __user *buf,static const struct proc_ops lcd_proc_ops = { .proc_show = lcd_proc_show, - .proc_write = lcd_proc_write, + .proc_write_buf = lcd_proc_write, };/* Video-Out */
@@ -1541,24 +1540,17 @@ static int video_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t video_proc_write (struct file *file,const char __user *buf, +static ssize_t video_proc_write (struct file *file,char *buf,size_t count,loff_t *pos) {struct toshiba_acpi_dev *dev =pde_data (file_inode (file)); -char *buffer; -char *cmd; +char *buffer = buf;int lcd_out =-1 , crt_out =-1 , tv_out =-1 ;int remain = count;int value;int ret;u32 video_out; - cmd =memdup_user_nul (buf, count); -if (IS_ERR (cmd)) -return PTR_ERR (cmd); - - buffer = cmd; -/* * Scan expression. Multiple expressions may be delimited with ; * NOTE: To keep scanning simple, invalid fields are ignored.
@@ -1577,8 +1569,6 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf, }while (remain && *(buffer -1 ) !=';' ); } -kfree (cmd); - ret =get_video_status (dev, &video_out);if (!ret) {unsigned int new_video_out = video_out;
@@ -1602,7 +1592,7 @@ static ssize_t video_proc_write(struct file *file, const char __user *buf,static const struct proc_ops video_proc_ops = { .proc_show = video_proc_show, - .proc_write = video_proc_write, + .proc_write_buf = video_proc_write, };/* Fan status */
@@ -1644,7 +1634,7 @@ static int fan_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t fan_proc_write (struct file *file,const char __user *buf, +static ssize_t fan_proc_write (struct file *file,char *buf,size_t count,loff_t *pos) {struct toshiba_acpi_dev *dev =pde_data (file_inode (file));
@@ -1653,8 +1643,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf,int value; len =min (count,sizeof (cmd) -1 ); -if (copy_from_user (cmd, buf, len)) -return -EFAULT ; +memcpy (cmd, buf, len); cmd[len] ='\0' ; if (sscanf(cmd, " force_on : %i", &value) != 1 ||
@@ -1671,7 +1660,7 @@ static ssize_t fan_proc_write(struct file *file, const char __user *buf,static const struct proc_ops fan_proc_ops = { .proc_show = fan_proc_show, - .proc_write = fan_proc_write, + .proc_write_buf = fan_proc_write, };/* Fan RPM */
@@ -1707,7 +1696,7 @@ static int keys_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t keys_proc_write (struct file *file,const char __user *buf, +static ssize_t keys_proc_write (struct file *file,char *buf,size_t count,loff_t *pos) {struct toshiba_acpi_dev *dev =pde_data (file_inode (file));
@@ -1716,8 +1705,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf,int value; len =min (count,sizeof (cmd) -1 ); -if (copy_from_user (cmd, buf, len)) -return -EFAULT ; +memcpy (cmd, buf, len); cmd[len] ='\0' ;if (sscanf (cmd," hotkey_ready : %i" , &value) ==1 && value ==0 )
@@ -1730,7 +1718,7 @@ static ssize_t keys_proc_write(struct file *file, const char __user *buf,static const struct proc_ops keys_proc_ops = { .proc_show = keys_proc_show, - .proc_write = keys_proc_write, + .proc_write_buf = keys_proc_write, };static int __maybe_unused version_proc_show (struct seq_file *m,void *v)
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 22/23 PNP: pnpbios: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to /proc/bus/pnp/<node> before it pins the entry, and take the node data from that copy. A node with more than PAGE_SIZE - 1 bytes of data can't be written anymore. I don't think there are any.
--- drivers/pnp/pnpbios/proc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/pnp/pnpbios/proc.c +3 -6
@@ -171,7 +171,7 @@ static int pnpbios_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t pnpbios_proc_write (struct file *file,const char __user *buf, +static ssize_t pnpbios_proc_write (struct file *file,char *buf,size_t count,loff_t *pos) {void *data =pde_data (file_inode (file));
@@ -191,10 +191,7 @@ static ssize_t pnpbios_proc_write(struct file *file, const char __user *buf, ret = -EINVAL ; goto out; } -if (copy_from_user (node->data, buf, count)) { - ret = -EFAULT ; - goto out; - } +memcpy (node->data, buf, count);if (pnp_bios_set_dev_node (node->handle, boot, node) !=0 ) { ret = -EINVAL ; goto out;
@@ -207,7 +204,7 @@ out:static const struct proc_ops pnpbios_proc_ops = { .proc_show = pnpbios_proc_show, - .proc_write = pnpbios_proc_write, + .proc_write_buf = pnpbios_proc_write, };int pnpbios_interface_attach_device (struct pnp_bios_node *node)
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 23/23 PNP: isapnp: let procfs copy out reads
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read from /proc/bus/isapnp/<card>/<dev> to userspace after it unpinned the entry.
--- drivers/pnp/isapnp/proc.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
drivers/pnp/isapnp/proc.c +7 -13
@@ -19,40 +19,34 @@ static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)return fixed_size_llseek (file, off, whence,256 ); } -static ssize_t isapnp_proc_bus_read (struct file *file,char __user * buf, +static ssize_t isapnp_proc_bus_read (struct file *file,char *buf,size_t nbytes,loff_t * ppos) {struct pnp_dev *dev =pde_data (file_inode (file));loff_t pos = *ppos; -int cnt, size =256 ; +int size =256 ; +size_t cnt;int ret;if (pos >= size)return 0 ;if (nbytes > size - pos) nbytes = size - pos; - cnt = nbytes; - -if (!access_ok (buf, cnt)) -return -EINVAL ; ret =isapnp_cfg_begin (dev->card->number, dev->number);if (ret)return ret; -for (; pos <256 && cnt >0 ; pos++, buf++, cnt--) { -unsigned char val; - val =isapnp_read_byte (pos); -put_user (val, buf); - } +for (cnt =0 ; cnt < nbytes; cnt++) + buf[cnt] =isapnp_read_byte (pos + cnt);isapnp_cfg_end (); - *ppos = pos; + *ppos = pos + nbytes;return nbytes; }static const struct proc_ops isapnp_proc_bus_proc_ops = { .proc_lseek = isapnp_proc_bus_lseek, - .proc_read = isapnp_proc_bus_read, + .proc_read_buf = isapnp_proc_bus_read, };static int isapnp_proc_attach_device (struct pnp_dev *dev)
Signature · 1 line
2.53.0
Christian Brauner
maintainerv2 cover proc: convert the driver entries (Part 4/7)
In reply to Christian BraunerPart 4/7 of "proc: move procfs to what kernfs does", on top of part 2 and independent of parts 3, 5 and 6:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
This converts the proc entries of nubus, zorro, PCI, md, dasd and cio, scsi, dell-smm, viafb, rndis, ipw2x00, sysrq, the input devices file and ALSA to what "proc: let procfs own the data path" set up. Afterwards the entries' code only runs with the entry pinned and never touches userspace memory. One patch per subsystem and method.
- procfs owns the seq_file of the nubus resource files, /proc/mdstat, the scsi host files, sg's allow_dio and def_reserved_size and ALSA's text entries. Their open and release hooks only do what is left, private data or the event count, and reading a scsi host file or an ALSA entry no longer holds up the removal of the host or the card.
- procfs copies in the writes of the PCI config space, /proc/dasd/statistics, cio_ignore and cio_settle, /proc/scsi/scsi, device_info and the host files, sg, viafb, rndis, ipw2x00's debug level, /proc/sysrq-trigger and ALSA's entries. Most of them just parse procfs' copy. Where a write larger than anything the entry parses now fails with -EINVAL from procfs the commit says so.
- procfs copies out the reads of /proc/bus/zorro, the PCI config space and ALSA's data entries.
- the PCI config space and ALSA's data entries take binary data at positions and keep doing that, PROC_ENTRY_SHORT_WRITES for writes in pieces, and ALSA's data entries ask for PROC_ENTRY_FULL_READS so that reading all of one at once keeps working. They hand procfs' buffer to the drivers, so struct snd_info_entry_ops changes along with them.
- procfs copies the ioctl arguments of PCI, esas2r's ATTONode file and dell-smm's i8k in and out. The PCI commands only pass values and the i8k ones encode the wrong sizes, both tables list what is really copied. ALSA's ioctl hook that no driver implements goes away.
- /proc/mdstat and /proc/bus/input/devices move their pollers to the wait queue procfs owns for the entry, which ends md's wakeup loop at unload, and the poll op of an ALSA info entry, which nothing implements, loses its poll_table.
The selftest writes to the file of a scsi_debug host from a buffer backed by userfaultfd and removes the host while procfs copies in. On a KASAN and lockdep kernel it fails without the series and passes with it. Build tested per commit on x86_64 and with W=1 on the touched objects on their own architectures. The entries I could get at in a VM behave the same with and without the series.
---
Changes in v2:
- md and Input let procfs own the wait queues of /proc/mdstat and /proc/bus/input/devices, md's wakeup loop at unload is gone and
/proc/mdstat is removed last, Input forgets the entry when it is
removed, and the poll op of an ALSA info entry loses its poll_table
- the scsi_debug selftest skips without /proc/scsi and removes the host
it added when its file can't be found
- Reviewed-by from Jiri on sysrq
- rebased onto v7.4-rc1
- Link to v1: https://patch.msgid.link/[email protected]
---
Christian Brauner (26):
nubus: let procfs own the seq_file of the resource files
zorro: let procfs copy out reads
PCI/proc: let procfs copy in config space writes
PCI/proc: let procfs copy out config space reads
PCI/proc: let procfs handle the ioctls
md: let procfs own the seq_file of /proc/mdstat
md: let procfs own the wait queue of /proc/mdstat s390/dasd: let procfs copy in writes to /proc/dasd/statistics s390/cio: let procfs copy in writes
scsi: let procfs own the seq_file of the host files
scsi: core: let procfs copy in writes
selftests/proc: check that a faulting writer doesn't hold up removal
scsi: sg: let procfs own the seq_file of allow_dio and def_reserved_size
scsi: sg: let procfs copy in writes
scsi: esas2r: let procfs copy the ioctl argument of the ATTONode file
hwmon: (dell-smm) let procfs copy the i8k ioctl arguments
fbdev: viafb: let procfs copy in writes
usb: gadget: function: rndis: let procfs copy in writes
wifi: ipw2x00: let procfs copy in writes to the debug level
tty: sysrq: let procfs copy in writes to /proc/sysrq-trigger
Input: let procfs own the wait queue of /proc/bus/input/devices
ALSA: info: let procfs own the seq_file of text entries
ALSA: info: let procfs copy in writes
ALSA: info: let procfs copy out reads of data entries
ALSA: info: drop the ioctl hook of data entries
ALSA: info: drop the poll_table from the info entry poll op
.../sound/kernel-api/writing-an-alsa-driver.rst | 10 +- drivers/hwmon/dell-smm-hwmon.c | 48 ++--- drivers/input/input.c | 13 +- drivers/md/md.c | 44 ++--- drivers/net/wireless/intel/ipw2x00/libipw_module.c | 7 +- drivers/nubus/proc.c | 12 +- drivers/pci/proc.c | 69 +++---- drivers/s390/block/dasd_proc.c | 17 +- drivers/s390/cio/blacklist.c | 33 +--- drivers/s390/cio/css.c | 4 +- drivers/scsi/esas2r/esas2r.h | 2 + drivers/scsi/esas2r/esas2r_ioctl.c | 58 +++--- drivers/scsi/esas2r/esas2r_main.c | 44 ++++- drivers/scsi/scsi_devinfo.c | 29 +-- drivers/scsi/scsi_proc.c | 55 ++---- drivers/scsi/sg.c | 44 ++--- drivers/tty/sysrq.c | 9 +- drivers/usb/gadget/function/rndis.c | 9 +- drivers/video/fbdev/via/viafbdev.c | 46 +++-- drivers/zorro/proc.c | 7 +- include/sound/gus.h | 2 +- include/sound/info.h | 9 +- sound/core/info.c | 59 +++--- sound/drivers/opl4/opl4_proc.c | 23 +-- sound/isa/gus/gus_dram.c | 7 +- sound/isa/gus/gus_mem_proc.c | 2 +- sound/pci/cs4281.c | 10 +- sound/pci/cs46xx/cs46xx_lib.c | 5 +- sound/pci/emu10k1/emuproc.c | 8 +- sound/pci/mixart/mixart.c | 10 +- sound/usb/mixer_scarlett2.c | 9 +- tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/config | 3 + .../selftests/proc/proc-remove-slow-writer.c | 209 +++++++++++++++++++++ 35 files changed, 503 insertions(+), 415 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261101-work-procfs-drivers-58cd83649658
prerequisite-change-id: 20261101-work-procfs-core-8fa4a4f412cf:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
Christian Brauner
maintainerPATCH RESEND v2 1/26 nubus: let procfs own the seq_file of the resource files
Get the inode from the file instead of ->private, declare the show function and let procfs open and free the seq_file.
--- drivers/nubus/proc.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/nubus/proc.c +2 -10
@@ -107,7 +107,7 @@ nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size)static int nubus_proc_rsrc_show (struct seq_file *m,void *v) { -struct inode *inode = m->private; +struct inode *inode =file_inode (m->file);struct nubus_proc_pde_data *pded; pded =pde_data (inode);
@@ -138,16 +138,8 @@ static int nubus_proc_rsrc_show(struct seq_file *m, void *v)return 0 ; } -static int nubus_rsrc_proc_open (struct inode *inode,struct file *file) -{ -return single_open (file, nubus_proc_rsrc_show, inode); -} -static const struct proc_ops nubus_rsrc_proc_ops = { - .proc_open = nubus_rsrc_proc_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = single_release, + .proc_show = nubus_proc_rsrc_show, }; void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 01/26] nubus: let procfs own the seq_file of the resource files
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Get the inode from the file instead of ->private, declare the show function and let procfs open and free the
seq_file.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Christian Brauner
maintainerPATCH RESEND v2 2/26 zorro: let procfs copy out reads
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read from /proc/bus/zorro/<slot> to userspace after it unpinned the entry.
--- drivers/zorro/proc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/zorro/proc.c +3 -4
@@ -28,7 +28,7 @@ proc_bus_zorro_lseek(struct file *file, loff_t off, int whence) }static ssize_t -proc_bus_zorro_read (struct file *file,char __user *buf,size_t nbytes,loff_t *ppos) +proc_bus_zorro_read (struct file *file,char *buf,size_t nbytes,loff_t *ppos) {struct zorro_dev *z =pde_data (file_inode (file));struct ConfigDev cd;
@@ -49,8 +49,7 @@ proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t * cd.cd_BoardAddr =cpu_to_be32 (zorro_resource_start (z)); cd.cd_BoardSize =cpu_to_be32 (zorro_resource_len (z)); -if (copy_to_user (buf, (void *)&cd + pos, nbytes)) -return -EFAULT ; +memcpy (buf, (void *)&cd + pos, nbytes); *ppos += nbytes;return nbytes;
@@ -58,7 +57,7 @@ proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *static const struct proc_ops bus_zorro_proc_ops = { .proc_lseek = proc_bus_zorro_lseek, - .proc_read = proc_bus_zorro_read, + .proc_read_buf = proc_bus_zorro_read, };static void *zorro_seq_start (struct seq_file *m,loff_t *pos)
Signature · 1 line
2.53.0
Re: [PATCH RESEND v2 02/26] zorro: let procfs copy out reads
Quoted 4 lines · Christian Brauner
Implement ->proc_read_buf() so procfs copies what is read from /proc/bus/zorro/<slot> to userspace after it unpinned the entry.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
[email protected]
AI reviewRe: [PATCH RESEND v2 02/26] zorro: let procfs copy out reads
In reply to Christian BraunerSashiko has reviewed this patch and found no issues.
Quoted 4 lines
Implement ->proc_read_buf() so procfs copies what is read from /proc/bus/zorro/<slot> to userspace after it unpinned the entry.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Christian Brauner
maintainerPATCH RESEND v2 3/26 PCI/proc: let procfs copy in config space writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and write the config space from that copy with get_unaligned_le16() and get_unaligned_le32() instead of get_user().
The copy holds at most PCI_CFG_SPACE_EXP_SIZE bytes. Larger writes come up short with PROC_ENTRY_SHORT_WRITES, like they did before because they were cut at the end of the config space.
A buffer that can't be read used to write zeroes to the config space and report success. It fails with -EFAULT now and nothing is written.
--- drivers/pci/proc.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-)
drivers/pci/proc.c +11 -21
@@ -16,6 +16,7 @@#include <linux/security.h> #include <linux/panic.h> #include <linux/sched.h> +#include <linux/unaligned.h> #include <asm/byteorder.h> #include "pci.h"
@@ -114,8 +115,8 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,return nbytes; } -static ssize_t proc_bus_pci_write (struct file *file,const char __user *buf, -size_t nbytes,loff_t *ppos) +static ssize_t proc_bus_pci_write (struct file *file,char *buf,size_t nbytes, +loff_t *ppos) {struct inode *ino =file_inode (file);struct pci_dev *dev =pde_data (ino);
@@ -145,51 +146,38 @@ static ssize_t proc_bus_pci_write(struct file *file, const char __user *buf, nbytes = size - pos; cnt = nbytes; -if (!access_ok (buf, cnt)) -return -EINVAL ; -pci_config_pm_runtime_get (dev);if ((pos &1 ) && cnt) { -unsigned char val; -get_user (val, buf); -pci_user_write_config_byte (dev, pos, val); +pci_user_write_config_byte (dev, pos, *buf); buf++; pos++; cnt--; }if ((pos &3 ) && cnt >2 ) { -__le16 val; -get_user (val, (__le16 __user *) buf); -pci_user_write_config_word (dev, pos,le16_to_cpu (val)); +pci_user_write_config_word (dev, pos,get_unaligned_le16 (buf)); buf +=2 ; pos +=2 ; cnt -=2 ; }while (cnt >=4 ) { -__le32 val; -get_user (val, (__le32 __user *) buf); -pci_user_write_config_dword (dev, pos,le32_to_cpu (val)); +pci_user_write_config_dword (dev, pos,get_unaligned_le32 (buf)); buf +=4 ; pos +=4 ; cnt -=4 ; }if (cnt >=2 ) { -__le16 val; -get_user (val, (__le16 __user *) buf); -pci_user_write_config_word (dev, pos,le16_to_cpu (val)); +pci_user_write_config_word (dev, pos,get_unaligned_le16 (buf)); buf +=2 ; pos +=2 ; cnt -=2 ; }if (cnt) { -unsigned char val; -get_user (val, buf); -pci_user_write_config_byte (dev, pos, val); +pci_user_write_config_byte (dev, pos, *buf); pos++; }
@@ -337,9 +325,11 @@ static int proc_bus_pci_release(struct inode *inode, struct file *file)#endif /* HAVE_PCI_MMAP */ static const struct proc_ops proc_bus_pci_ops = { + .proc_flags =PROC_ENTRY_SHORT_WRITES , .proc_lseek = proc_bus_pci_lseek, .proc_read = proc_bus_pci_read, - .proc_write = proc_bus_pci_write, + .proc_write_buf = proc_bus_pci_write, + .proc_write_size =PCI_CFG_SPACE_EXP_SIZE , .proc_ioctl = proc_bus_pci_ioctl, #ifdef CONFIG_COMPAT .proc_compat_ioctl = proc_bus_pci_ioctl,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 03/26] PCI/proc: let procfs copy in config space writes
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and write the config space from that copy with
get_unaligned_le16()andget_unaligned_le32()instead ofget_user().
Quoted 8 lines
The copy holds at most
PCI_CFG_SPACE_EXP_SIZEbytes. Larger writes come up short withPROC_ENTRY_SHORT_WRITES, like they did before because they were cut at the end of the config space.A buffer that can't be read used to write zeroes to the config space and report success. It fails with
-EFAULTnow and nothing is written.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Christian Brauner
maintainerPATCH RESEND v2 4/26 PCI/proc: let procfs copy out config space reads
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry, and read the config space into procfs' buffer with put_unaligned_le16() and put_unaligned_le32() instead of put_user(). A read into a buffer that can't be written used to report success. It fails with -EFAULT now. A page holds all of the config space, so a single read of it still works, libpci treats a short read as an error.
--- drivers/pci/proc.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/pci/proc.c +8 -11
@@ -29,8 +29,8 @@ static loff_t proc_bus_pci_lseek(struct file *file, loff_t off, int whence)return fixed_size_llseek (file, off, whence, dev->cfg_size); } -static ssize_t proc_bus_pci_read (struct file *file,char __user *buf, -size_t nbytes,loff_t *ppos) +static ssize_t proc_bus_pci_read (struct file *file,char *buf,size_t nbytes, +loff_t *ppos) {struct pci_dev *dev =pde_data (file_inode (file));unsigned int pos, cnt, size;
@@ -60,15 +60,12 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf, nbytes = size - pos; cnt = nbytes; -if (!access_ok (buf, cnt)) -return -EINVAL ; -pci_config_pm_runtime_get (dev);if ((pos &1 ) && cnt) {unsigned char val;pci_user_read_config_byte (dev, pos, &val); -put_user (val, buf); + *buf = val; buf++; pos++; cnt--;
@@ -77,7 +74,7 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,if ((pos &3 ) && cnt >2 ) {unsigned short val;pci_user_read_config_word (dev, pos, &val); -put_user (cpu_to_le16 (val), (__le16 __user *) buf); +put_unaligned_le16 (val, buf); buf +=2 ; pos +=2 ; cnt -=2 ;
@@ -86,7 +83,7 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,while (cnt >=4 ) {unsigned int val;pci_user_read_config_dword (dev, pos, &val); -put_user (cpu_to_le32 (val), (__le32 __user *) buf); +put_unaligned_le32 (val, buf); buf +=4 ; pos +=4 ; cnt -=4 ;
@@ -96,7 +93,7 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,if (cnt >=2 ) {unsigned short val;pci_user_read_config_word (dev, pos, &val); -put_user (cpu_to_le16 (val), (__le16 __user *) buf); +put_unaligned_le16 (val, buf); buf +=2 ; pos +=2 ; cnt -=2 ;
@@ -105,7 +102,7 @@ static ssize_t proc_bus_pci_read(struct file *file, char __user *buf,if (cnt) {unsigned char val;pci_user_read_config_byte (dev, pos, &val); -put_user (val, buf); + *buf = val; pos++; }
@@ -327,7 +324,7 @@ static int proc_bus_pci_release(struct inode *inode, struct file *file)static const struct proc_ops proc_bus_pci_ops = { .proc_flags =PROC_ENTRY_SHORT_WRITES , .proc_lseek = proc_bus_pci_lseek, - .proc_read = proc_bus_pci_read, + .proc_read_buf = proc_bus_pci_read, .proc_write_buf = proc_bus_pci_write, .proc_write_size =PCI_CFG_SPACE_EXP_SIZE , .proc_ioctl = proc_bus_pci_ioctl,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 04/26] PCI/proc: let procfs copy out config space reads
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Implement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry, and read the config space into procfs' buffer with
put_unaligned_le16()andput_unaligned_le32()instead ofput_user(). A read into a buffer that can't be written used to report success. It fails with-EFAULTnow. A page holds all of the config space, so a single read of it still works, libpci treats a short read as an error.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Christian Brauner
maintainerPATCH RESEND v2 5/26 PCI/proc: let procfs handle the ioctls
In reply to Christian BraunerThe PCIIOC_* commands take and return plain values and don't touch userspace memory. Implement ->proc_ioctl_buf() and list them with nothing to copy. 32-bit tasks go through the same table, so the compat hook goes away. Unknown commands fail with -ENOTTY from procfs now instead of -EINVAL, and instead of -EPERM under lockdown, since they never reach the handler.
--- drivers/pci/proc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/pci/proc.c +12 -6
@@ -192,8 +192,7 @@ struct pci_filp_private { };#endif /* HAVE_PCI_MMAP */ -static long proc_bus_pci_ioctl (struct file *file,unsigned int cmd, -unsigned long arg) +static long proc_bus_pci_ioctl (struct file *file,unsigned int cmd,void *arg) {struct pci_dev *dev =pde_data (file_inode (file));#ifdef HAVE_PCI_MMAP
@@ -321,16 +320,23 @@ static int proc_bus_pci_release(struct inode *inode, struct file *file) }#endif /* HAVE_PCI_MMAP */ +/* The commands take and return plain values. */ +static const struct proc_ioctl_arg proc_bus_pci_ioctl_args[] = { +PROC_IOCTL_ARG (PCIIOC_CONTROLLER ,0 ,0 ), +PROC_IOCTL_ARG (PCIIOC_MMAP_IS_IO ,0 ,0 ), +PROC_IOCTL_ARG (PCIIOC_MMAP_IS_MEM ,0 ,0 ), +PROC_IOCTL_ARG (PCIIOC_WRITE_COMBINE ,0 ,0 ), +}; +static const struct proc_ops proc_bus_pci_ops = { .proc_flags =PROC_ENTRY_SHORT_WRITES , .proc_lseek = proc_bus_pci_lseek, .proc_read_buf = proc_bus_pci_read, .proc_write_buf = proc_bus_pci_write, .proc_write_size =PCI_CFG_SPACE_EXP_SIZE , - .proc_ioctl = proc_bus_pci_ioctl, -#ifdef CONFIG_COMPAT - .proc_compat_ioctl = proc_bus_pci_ioctl, -#endif + .proc_ioctl_buf = proc_bus_pci_ioctl, + .proc_ioctl_args = proc_bus_pci_ioctl_args, + .proc_nr_ioctl_args =ARRAY_SIZE (proc_bus_pci_ioctl_args), #ifdef HAVE_PCI_MMAP .proc_open = proc_bus_pci_open, .proc_release = proc_bus_pci_release,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 05/26] PCI/proc: let procfs handle the ioctls
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
The PCIIOC_* commands take and return plain values and don't touch userspace memory. Implement ->proc_ioctl_buf() and list them with nothing to copy. 32-bit tasks go through the same table, so the compat hook goes away. Unknown commands fail with
-ENOTTYfrom procfs now instead of-EINVAL, and instead of-EPERMunder lockdown, since they never reach the handler.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Christian Brauner
maintainerPATCH RESEND v2 6/26 md: let procfs own the seq_file of /proc/mdstat
In reply to Christian BraunerDeclare the seq_operations and let procfs open and free the seq_file. ->proc_open() only records the event count for ->proc_poll() now.
--- drivers/md/md.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/md/md.c +4 -11
@@ -9167,18 +9167,13 @@ static const struct seq_operations md_seq_ops = { .show = md_seq_show, }; +/* procfs opens the seq_file */ static int md_seq_open (struct inode *inode,struct file *file) { -struct seq_file *seq; -int error; - - error =seq_open (file, &md_seq_ops); -if (error) -return error; +struct seq_file *seq = file->private_data; - seq = file->private_data; seq->poll_event =atomic_read (&md_event_count); -return error; +return 0 ; }static int md_unloading;
@@ -9200,10 +9195,8 @@ static __poll_t mdstat_poll(struct file *filp, poll_table *wait) }static const struct proc_ops mdstat_proc_ops = { + .proc_seq_ops = &md_seq_ops, .proc_open = md_seq_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = seq_release, .proc_poll = mdstat_poll, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 06/26] md: let procfs own the seq_file of /proc/mdstat
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Declare the
seq_operationsand let procfs open and free theseq_file. ->proc_open() only records the event count for ->proc_poll() now.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Christian Brauner
maintainerPATCH RESEND v2 7/26 md: let procfs own the wait queue of /proc/mdstat
In reply to Christian Braunermdstat_poll() sleeps the poller on md_event_waiters and md_exit() has to wake it in a loop until nobody is left on the queue, because the queue goes away with the module. procfs owns the queue poll() uses now, it outlives the module, and a poll of the removed entry reports EPOLLERR | EPOLLPRI, so md_new_event() wakes the pollers through proc_poll_notify() and the loop and md_unloading go.
md_exit() removes /proc/mdstat last now. A sysfs store on an inactive array doesn't hold the module, so it can still reach md_new_event() while md_exit() runs, until destroy_workqueue() has waited for the last array to go, and a wake-up through a removed entry is a use after free. The static queue didn't mind that, the entry does.
--- drivers/md/md.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-)
drivers/md/md.c +8 -21
@@ -351,12 +351,12 @@ static bool check_new_feature = true;* start array, stop array, error, add device, remove device, * start build, activate spare */ -static DECLARE_WAIT_QUEUE_HEAD (md_event_waiters); +static struct proc_dir_entry *mdstat_entry;static atomic_t md_event_count;void md_new_event (void ) {atomic_inc (&md_event_count); -wake_up (&md_event_waiters); +proc_poll_notify (mdstat_entry); }EXPORT_SYMBOL_GPL (md_new_event);
@@ -9176,16 +9176,11 @@ static int md_seq_open(struct inode *inode, struct file *file)return 0 ; } -static int md_unloading;static __poll_t mdstat_poll (struct file *filp,poll_table *wait) {struct seq_file *seq = filp->private_data;__poll_t mask; -if (md_unloading) -return EPOLLIN |EPOLLRDNORM |EPOLLERR |EPOLLPRI ; -poll_wait (filp, &md_event_waiters, wait); -/* always allow read */ mask =EPOLLIN |EPOLLRDNORM ;
@@ -10765,7 +10760,7 @@ static void md_geninit(void) {pr_debug ("md: sizeof(mdp_super_t) = %d\n" , (int )sizeof (mdp_super_t)); -proc_create ("mdstat" ,S_IRUGO ,NULL , &mdstat_proc_ops); + mdstat_entry =proc_create ("mdstat" ,S_IRUGO ,NULL , &mdstat_proc_ops); }static int __init md_init (void )
@@ -11074,25 +11069,12 @@ void md_autostart_arrays(int part) static __exit void md_exit(void) {struct mddev *mddev; -int delay =1 ;unregister_blkdev (MD_MAJOR ,"md" );unregister_blkdev (mdp_major,"mdp" );unregister_reboot_notifier (&md_notifier);unregister_sysctl_table (raid_table_header); -/* We cannot unload the modules while some process is -* waiting for us in select() or poll() - wake them up -*/ - md_unloading =1 ; -while (waitqueue_active (&md_event_waiters)) { -/* not safe to leave yet */ -wake_up (&md_event_waiters); -msleep (delay); - delay += delay; - } -remove_proc_entry ("mdstat" ,NULL ); -spin_lock (&all_mddevs_lock);list_for_each_entry (mddev, &all_mddevs, all_mddevs) {if (!mddev_get (mddev))
@@ -11112,6 +11094,11 @@ static __exit void md_exit(void)spin_unlock (&all_mddevs_lock);destroy_workqueue (md_misc_wq); +/* +* Only now can nothing reach md_new_event() anymore, which wakes the +* pollers of /proc/mdstat through its entry. +*/ +remove_proc_entry ("mdstat" ,NULL );md_bitmap_exit (); }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 07/26] md: let procfs own the wait queue of /proc/mdstat
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] md: use-after-free on md_misc_wq in md_seq_show() during md_exit() - [High] md: use-after-free on…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] md: use-after-free on md_misc_wq in md_seq_show() during md_exit()
- [High] md: use-after-free on mdstat_entry in md_new_event() during md_exit() --
commit d5381c9dd419c5377924fd70f1baf55ca30c4844
Author: Christian Brauner <[email protected]>
md: let procfs own the wait queue of /proc/mdstat
This commit replaces the module-owned md_event_waiters wait queue with proc_poll_notify() on the /proc/mdstat proc_dir_entry, removing the md_unloading flag and wait loop on module exit. It also moves the removal of /proc/mdstat in md_exit() to after destroy_workqueue(md_misc_wq) so that late md_new_event() calls do not dereference a removed proc entry.
Quoted 4 lines
drivers/md/md.c +0
-0
[ ... ]
Quoted 12 lines
drivers/md/md.c +0
-2@@ -11074,25 +11069,12 @@ void md_autostart_arrays(int part) static __exit void md_exit(void) {struct mddev *mddev; -int delay =1 ;unregister_blkdev (MD_MAJOR ,"md" );unregister_blkdev (mdp_major,"mdp" );unregister_reboot_notifier (&md_notifier);unregister_sysctl_table (raid_table_header); -/* We cannot unload the modules while some process is
drivers/md/md.c void md_autostart_arrays(int part) · line 11094
Quoted 10 lines
drivers/md/md.c +0
-10-* waiting for us in select() or poll() - wake them up -*/ - md_unloading =1 ; -while (waitqueue_active (&md_event_waiters)) { -/* not safe to leave yet */ -wake_up (&md_event_waiters); -msleep (delay); - delay += delay; - } -remove_proc_entry ("mdstat" ,NULL );
[Severity: High]
If remove_proc_entry("mdstat", NULL) is moved after the all_mddevs teardown loop and destroy_workqueue(md_misc_wq), can a concurrent reader of /proc/mdstat trigger a use-after-free on md_misc_wq and leak the mddev?
Previously, calling remove_proc_entry("mdstat", NULL) before iterating over all_mddevs waited in proc_entry_rundown() for all active seq_file readers in md_seq_show() to complete before mddev teardown started. Reading /proc/mdstat pins the proc_dir_entry rather than holding a module reference on md_mod.
In drivers/md/md.c:md_seq_show(), a reader takes a reference on mddev->active and drops all_mddevs_lock while formatting output:
drivers/md/md.c:md_seq_show() {
...
mddev = list_entry(v, struct mddev, all_mddevs);
if (!mddev_get(mddev))
return 0;
spin_unlock(&all_mddevs_lock);
...
spin_lock(&all_mddevs_lock);
mddev_put_locked(mddev);
return 0;
}If md_exit() runs while md_seq_show() is between mddev_get() and mddev_put_locked() on an inactive array:
1. md_exit() calls mddev_get(mddev) (incrementing mddev->active from 1 to 2), drops all_mddevs_lock, calls export_array(mddev) (which also mutates mddev->disks, mddev->raid_disks, and mddev->major_version without holding mddev->lock while md_seq_show() reads them), clears mddev->ctime = 0 and mddev->hold_active = 0, and calls mddev_put_locked(mddev).
2. Because md_seq_show() still holds its reference, atomic_dec_and_test(&mddev->active) in md_exit() drops mddev->active from 2 to 1 and returns false, so __mddev_put() is not called and mddev->del_work is not queued on md_misc_wq.
3. md_exit() then calls destroy_workqueue(md_misc_wq) and blocks in remove_proc_entry("mdstat", NULL) waiting for md_seq_show() to finish.
4. When md_seq_show() finishes and calls mddev_put_locked(mddev), mddev->active drops from 1 to 0 and __mddev_put() queues mddev->del_work onto the already-destroyed md_misc_wq workqueue:
drivers/md/md.c:__mddev_put() {
...
set_bit(MD_DELETED, &mddev->flags);
queue_work(md_misc_wq, &mddev->del_work);
}drivers/md/md.c static __exit void md_exit(void) · line 11101
Quoted 9 lines
drivers/md/md.c +5
-0@@ -11112,6 +11094,11 @@ static __exit void md_exit(void)spin_unlock (&all_mddevs_lock);destroy_workqueue (md_misc_wq); +/* +* Only now can nothing reach md_new_event() anymore, which wakes the +* pollers of /proc/mdstat through its entry. +*/ +remove_proc_entry ("mdstat" ,NULL );
[Severity: High]
Does destroy_workqueue(md_misc_wq) guarantee that an in-flight sysfs store on an inactive array has finished before remove_proc_entry("mdstat", NULL) frees mdstat_entry?
In drivers/md/md.c:md_attr_store(), the caller holds a reference on mddev->active across entry->store() (where md_new_event() is called) and only drops it afterward:
drivers/md/md.c:md_attr_store() {
...
spin_lock(&all_mddevs_lock);
if (!mddev_get(mddev)) {
spin_unlock(&all_mddevs_lock);
if (kn)
sysfs_unbreak_active_protection(kn);
return -EBUSY;
}
spin_unlock(&all_mddevs_lock);
rv = entry->store(mddev, page, length);
if (kn)
sysfs_unbreak_active_protection(kn);
mddev_put(mddev);
return rv;
}If md_attr_store() acquires mddev->active before md_exit() reaches mddev_put_locked(mddev) (for example, while md_exit() drops all_mddevs_lock around export_array(mddev)), md_exit()'s call to mddev_put_locked(mddev) only decrements mddev->active from 2 to 1 and does not queue mddev->del_work onto md_misc_wq.
Similarly, if the inactive array had bound rdevs, export_array() moves them to mddev->deleting via md_kick_rdev_from_array() without draining mddev->deleting or dropping rdev->kobj, which holds a parent reference on mddev->kobj; if rdev_attr_store() is in flight, kobject_put(&mddev->kobj) in mddev_delayed_delete() returns without waiting for rdev_attr_store() to finish.
In either case, destroy_workqueue(md_misc_wq) returns while the sysfs store is still running, remove_proc_entry("mdstat", NULL) frees mdstat_entry, and the in-flight store can then call md_new_event()->proc_poll_notify(mdstat_entry) on the freed mdstat_entry (followed by md_attr_store() calling mddev_put(mddev) and queuing mddev->del_work onto the destroyed md_misc_wq).
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Christian Brauner
maintainerPATCH RESEND v2 8/26 s390/dasd: let procfs copy in writes to /proc/dasd/statistics
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and parse the command from that copy. Commands longer than PAGE_SIZE - 1 bytes are rejected now instead of cut at 64k.
--- drivers/s390/block/dasd_proc.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/s390/block/dasd_proc.c +6 -11
@@ -15,7 +15,6 @@#include <linux/slab.h> #include <linux/string.h> #include <linux/seq_file.h> -#include <linux/vmalloc.h> #include <linux/proc_fs.h> #include <asm/debug.h>
@@ -247,17 +246,15 @@ static int dasd_stats_proc_show(struct seq_file *m, void *v) }static ssize_t dasd_stats_proc_write (struct file *file, -const char __user *user_buf,size_t user_len,loff_t *pos) +char *buffer,size_t user_len,loff_t *pos) {#ifdef CONFIG_DASD_PROFILE -char *buffer, *str; +char *str;int rc; -if (user_len >65536 ) - user_len =65536 ; - buffer =dasd_get_user_string (user_buf, user_len); -if (IS_ERR (buffer)) -return PTR_ERR (buffer); +/* strip linefeed */ +if (user_len && buffer[user_len -1 ] =='\n' ) + buffer[user_len -1 ] =0 ;/* check for valid verbs */ str =skip_spaces (buffer);
@@ -296,13 +293,11 @@ static ssize_t dasd_stats_proc_write(struct file *file, pr_info("The statistics have been reset\n"); }else goto out_parse_error; -vfree (buffer);return user_len; out_parse_error: rc = -EINVAL ;pr_warn ("%s is not a supported value for /proc/dasd/statistics\n" , str); out_error: -vfree (buffer);return rc;#else pr_warn ("/proc/dasd/statistics: is not activated in this kernel\n" );
@@ -312,7 +307,7 @@ out_error:static const struct proc_ops dasd_stats_proc_ops = { .proc_show = dasd_stats_proc_show, - .proc_write = dasd_stats_proc_write, + .proc_write_buf = dasd_stats_proc_write, };/*
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 08/26] s390/dasd: let procfs copy in writes to /proc/dasd/statistics
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and parse the command from that copy. Commands longer than
PAGE_SIZE- 1 bytes are rejected now instead of cut at 64k.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Christian Brauner
maintainerPATCH RESEND v2 9/26 s390/cio: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for cio_ignore and cio_settle so procfs copies in what is written before it pins the entry. cio_ignore parses the list from that copy, up to the first NUL like strncpy_from_user() handed it to it before. Writes larger than 64k still come up short, now through PROC_ENTRY_SHORT_WRITES. Writes to cio_settle larger than PAGE_SIZE - 1 bytes fail with -EINVAL now, it never looked at what was written.
--- drivers/s390/cio/blacklist.c | 33 ++++++++++----------------------- drivers/s390/cio/css.c | 4 ++-- 2 files changed, 12 insertions(+), 25 deletions(-)
drivers/s390/cio/blacklist.c +10 -23
@@ -12,7 +12,7 @@#include <linux/hex.h> #include <linux/init.h> -#include <linux/vmalloc.h> +#include <linux/sizes.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/ctype.h>
@@ -355,39 +355,24 @@ cio_ignore_proc_seq_show(struct seq_file *s, void *it) }static ssize_t -cio_ignore_write (struct file *file,const char __user *user_buf, +cio_ignore_write (struct file *file,char *buf,size_t user_len,loff_t *offset) { -char *buf; -ssize_t rc, ret, i; +ssize_t ret, i;if (*offset)return -EINVAL ; -if (user_len >65536 ) - user_len =65536 ; - buf =vzalloc (user_len +1 );/* maybe better use the stack? */ -if (buf ==NULL ) -return -ENOMEM ; -if (strncpy_from_user (buf, user_buf, user_len) <0 ) { - rc = -EFAULT ; - goto out_free; - } - - i = user_len -1 ; +/* the parser never saw what follows a NUL */ + i =strnlen (buf, user_len) -1 ;while ((i >=0 ) && (isspace (buf[i]) || (buf[i] ==0 ))) { buf[i] ='\0' ; i--; } ret =blacklist_parse_proc_parameters (buf);if (ret) - rc = ret; -else - rc = user_len; - -out_free: -vfree (buf); -return rc; +return ret; +return user_len; }static const struct seq_operations cio_ignore_proc_seq_ops = {
@@ -398,9 +383,11 @@ static const struct seq_operations cio_ignore_proc_seq_ops = { };static const struct proc_ops cio_ignore_proc_ops = { + .proc_flags =PROC_ENTRY_SHORT_WRITES , .proc_seq_ops = &cio_ignore_proc_seq_ops, .proc_state_size =sizeof (struct ccwdev_iter ), - .proc_write = cio_ignore_write, + .proc_write_buf = cio_ignore_write, + .proc_write_size =SZ_64K , }; static int
drivers/s390/cio/css.c +2 -2
@@ -1278,7 +1278,7 @@ static int __init channel_subsystem_init_sync(void)subsys_initcall_sync (channel_subsystem_init_sync);#ifdef CONFIG_PROC_FS -static ssize_t cio_settle_write (struct file *file,const char __user *buf, +static ssize_t cio_settle_write (struct file *file,char *buf,size_t count,loff_t *ppos) {int ret;
@@ -1292,7 +1292,7 @@ static ssize_t cio_settle_write(struct file *file, const char __user *buf,static const struct proc_ops cio_settle_proc_ops = { .proc_open = nonseekable_open, - .proc_write = cio_settle_write, + .proc_write_buf = cio_settle_write, };static int __init cio_settle_init (void )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 09/26] s390/cio: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Implement ->proc_write_buf() for
cio_ignoreandcio_settleso procfs copies in what is written before it pins the entry.cio_ignoreparses the list from that copy, up to the first NUL likestrncpy_from_user()handed it to it before. Writes larger than 64k still come up short, now throughPROC_ENTRY_SHORT_WRITES. Writes tocio_settlelarger thanPAGE_SIZE- 1 bytes fail with-EINVALnow, it never looked at what was written.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Christian Brauner
maintainerPATCH RESEND v2 10/26 scsi: let procfs own the seq_file of the host files
In reply to Christian BraunerDeclare the show function and let procfs open and free the seq_file of /proc/scsi/<driver>/<host>. ->proc_open() only preallocates the buffer now. Reading the file then no longer holds up its removal when the host goes away.
--- drivers/scsi/scsi_proc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/scsi/scsi_proc.c +3 -5
@@ -94,10 +94,10 @@ static int proc_scsi_show(struct seq_file *m, void *v)return shost->hostt->show_info (m, shost); } +/* procfs opens the seq_file */ static int proc_scsi_host_open (struct inode *inode,struct file *file) { -return single_open_size (file, proc_scsi_show,pde_data (inode), -4 *PAGE_SIZE ); +return seq_preallocate (file->private_data,4 *PAGE_SIZE ); } static struct scsi_proc_entry *
@@ -140,10 +140,8 @@ scsi_template_proc_dir(const struct scsi_host_template *sht)EXPORT_SYMBOL_GPL (scsi_template_proc_dir);static const struct proc_ops proc_scsi_ops = { + .proc_show = proc_scsi_show, .proc_open = proc_scsi_host_open, - .proc_release = single_release, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_write = proc_scsi_host_write };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 10/26] scsi: let procfs own the seq_file of the host files
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Declare the show function and let procfs open and free the
seq_fileof /proc/scsi/<driver>/<host>. ->proc_open() only preallocates the buffer now. Reading the file then no longer holds up its removal when the host goes away.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Christian Brauner
maintainerPATCH RESEND v2 11/26 scsi: core: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for /proc/scsi/scsi, /proc/scsi/device_info and the host files so procfs copies in what is written before it pins the entry, and parse what was written from that copy. /proc/scsi/scsi and device_info take up to PAGE_SIZE bytes like before. The host files pass the copy to ->write_info(), writes to them that are larger than PAGE_SIZE - 1 bytes fail with -EINVAL from procfs instead of -EOVERFLOW.
--- drivers/scsi/scsi_devinfo.c | 29 +++++----------------------- drivers/scsi/scsi_proc.c | 47 +++++++++++---------------------------------- 2 files changed, 16 insertions(+), 60 deletions(-)
drivers/scsi/scsi_devinfo.c +5 -24
@@ -678,39 +678,20 @@ static const struct seq_operations scsi_devinfo_seq_ops = {* To use, echo "vendor:model:flag" > /proc/scsi/device_info */ static ssize_t proc_scsi_devinfo_write (struct file *file, -const char __user *buf, +char *buffer,size_t length,loff_t *ppos) { -char *buffer; -ssize_t err = length; - -if (!buf || length>PAGE_SIZE ) +if (length ==PAGE_SIZE && buffer[PAGE_SIZE -1 ])return -EINVAL ; - buffer =kmalloc (PAGE_SIZE ,GFP_KERNEL ); -if (!buffer) -return -ENOMEM ; -if (copy_from_user (buffer, buf, length)) { - err =-EFAULT ; - goto out; - } - -if (length <PAGE_SIZE ) - buffer[length] ='\0' ; -else if (buffer[PAGE_SIZE -1 ]) { - err = -EINVAL ; - goto out; - }scsi_dev_info_list_add_str (buffer); - -out: -kfree (buffer); -return err; +return length; }static const struct proc_ops scsi_devinfo_proc_ops = { .proc_seq_ops = &scsi_devinfo_seq_ops, - .proc_write = proc_scsi_devinfo_write, + .proc_write_buf = proc_scsi_devinfo_write, + .proc_write_size =PAGE_SIZE , };#endif /* CONFIG_SCSI_PROC_FS */
drivers/scsi/scsi_proc.c +11 -36
103 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 11/26] scsi: core: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Implement ->proc_write_buf() for
/proc/scsi/scsi,/proc/scsi/device_infoand the host files so procfs copies in what is written before it pins the entry, and parse what was written from that copy./proc/scsi/scsianddevice_infotake up toPAGE_SIZEbytes like before. The host files pass the copy to ->write_info(), writes to them that are larger thanPAGE_SIZE- 1 bytes fail with-EINVALfrom procfs instead of-EOVERFLOW.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Christian Brauner
maintainerPATCH RESEND v2 12/26 selftests/proc: check that a faulting writer doesn't hold up removal
In reply to Christian BraunerWrite to /proc/scsi/scsi_debug/<host> from a buffer whose page is backed by userfaultfd and remove the host while procfs copies in what is written:
- removing the entry doesn't wait for the writer
- the write fails with -EIO once the fault is resolved
The test loads scsi_debug if it isn't there and skips without it or without /proc/scsi.
--- tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/config | 3 + .../selftests/proc/proc-remove-slow-writer.c | 209 +++++++++++++++++++++ 4 files changed, 214 insertions(+)
tools/testing/selftests/proc/.gitignore +1 -0
@@ -25,6 +25,7 @@ /proc-remove-slow-reader /proc-remove-mapped /proc-remove-slow-readlink +/proc-remove-slow-writer /read /self /setns-dcache
tools/testing/selftests/proc/Makefile +1 -0
@@ -36,5 +36,6 @@ TEST_GEN_PROGS += proc-remove-slow-sysctl TEST_GEN_PROGS += proc-remove-slow-reader TEST_GEN_PROGS += proc-remove-mapped TEST_GEN_PROGS += proc-remove-slow-readlink +TEST_GEN_PROGS += proc-remove-slow-writer include ../lib.mk
tools/testing/selftests/proc/config +3 -0
@@ -1,4 +1,7 @@ CONFIG_PROC_FS=y +CONFIG_SCSI=y +CONFIG_SCSI_PROC_FS=y +CONFIG_SCSI_DEBUG=m CONFIG_NET_NS=y CONFIG_IPV6=y CONFIG_TUN=y
tools/testing/selftests/proc/proc-remove-slow-writer.c new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 12/26] selftests/proc: check that a faulting writer doesn't hold up removal
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Write to /proc/scsi/scsi_debug/<host> from a buffer whose page is backed by userfaultfd and remove the host while procfs copies in what is written:
Quoted 8 lines
- removing the entry doesn't wait for the writer
- the write fails with
-EIOonce the fault is resolvedThe test loads
scsi_debugif it isn't there and skips without it or without/proc/scsi.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Christian Brauner
maintainerPATCH RESEND v2 13/26 scsi: sg: let procfs own the seq_file of allow_dio and def_reserved_size
In reply to Christian BraunerPass the integer they show as the data of the entry and declare the show function, procfs then opens and frees the seq_file. That makes the open functions unnecessary.
--- drivers/scsi/sg.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/scsi/sg.c +6 -22
@@ -2288,26 +2288,18 @@ sg_get_dev(int dev)#ifdef CONFIG_SCSI_PROC_FS static int sg_proc_seq_show_int (struct seq_file *s,void *v); -static int sg_proc_single_open_adio (struct inode *inode,struct file *file);static ssize_t sg_proc_write_adio (struct file *filp,const char __user *buffer,size_t count,loff_t *off);static const struct proc_ops adio_proc_ops = { - .proc_open = sg_proc_single_open_adio, - .proc_read = seq_read, - .proc_lseek = seq_lseek, + .proc_show = sg_proc_seq_show_int, .proc_write = sg_proc_write_adio, - .proc_release = single_release, }; -static int sg_proc_single_open_dressz (struct inode *inode,struct file *file);static ssize_t sg_proc_write_dressz (struct file *filp,const char __user *buffer,size_t count,loff_t *off);static const struct proc_ops dressz_proc_ops = { - .proc_open = sg_proc_single_open_dressz, - .proc_read = seq_read, - .proc_lseek = seq_lseek, + .proc_show = sg_proc_seq_show_int, .proc_write = sg_proc_write_dressz, - .proc_release = single_release, };static int sg_proc_seq_show_version (struct seq_file *s,void *v);
@@ -2348,9 +2340,11 @@ sg_proc_init(void)if (!p)return 1 ; -proc_create ("allow_dio" ,S_IRUGO |S_IWUSR , p, &adio_proc_ops); +proc_create_data ("allow_dio" ,S_IRUGO |S_IWUSR , p, &adio_proc_ops, + &sg_allow_dio);proc_create_seq ("debug" ,S_IRUGO , p, &debug_seq_ops); -proc_create ("def_reserved_size" ,S_IRUGO |S_IWUSR , p, &dressz_proc_ops); +proc_create_data ("def_reserved_size" ,S_IRUGO |S_IWUSR , p, + &dressz_proc_ops, &def_reserved_size);proc_create_single ("device_hdr" ,S_IRUGO , p, sg_proc_seq_show_devhdr);proc_create_seq ("devices" ,S_IRUGO , p, &dev_seq_ops);proc_create_seq ("device_strs" ,S_IRUGO , p, &devstrs_seq_ops);
@@ -2365,11 +2359,6 @@ static int sg_proc_seq_show_int(struct seq_file *s, void *v)return 0 ; } -static int sg_proc_single_open_adio (struct inode *inode,struct file *file) -{ -return single_open (file, sg_proc_seq_show_int, &sg_allow_dio); -} -static ssize_t sg_proc_write_adio (struct file *filp,const char __user *buffer,size_t count,loff_t *off)
@@ -2386,11 +2375,6 @@ sg_proc_write_adio(struct file *filp, const char __user *buffer,return count; } -static int sg_proc_single_open_dressz (struct inode *inode,struct file *file) -{ -return single_open (file, sg_proc_seq_show_int, &def_reserved_size); -} -static ssize_t sg_proc_write_dressz (struct file *filp,const char __user *buffer,size_t count,loff_t *off)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 13/26] scsi: sg: let procfs own the seq_file of allow_dio and def_reserved_size
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Pass the integer they show as the data of the entry and declare the show function, procfs then opens and frees the
seq_file. That makes the open functions unnecessary.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Christian Brauner
maintainerPATCH RESEND v2 14/26 scsi: sg: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for allow_dio and def_reserved_size so procfs copies in what is written before it pins the entry, and parse the number from that copy.
kstrtoul_from_user() looked at the first 66 bytes of whatever was written. Now the whole write is parsed, and anything larger than PAGE_SIZE - 1 bytes fails with -EINVAL from procfs before the capability check.
--- drivers/scsi/sg.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/scsi/sg.c +8 -8
@@ -2288,18 +2288,18 @@ sg_get_dev(int dev)#ifdef CONFIG_SCSI_PROC_FS static int sg_proc_seq_show_int (struct seq_file *s,void *v); -static ssize_t sg_proc_write_adio (struct file *filp,const char __user *buffer, +static ssize_t sg_proc_write_adio (struct file *filp,char *buffer,size_t count,loff_t *off);static const struct proc_ops adio_proc_ops = { .proc_show = sg_proc_seq_show_int, - .proc_write = sg_proc_write_adio, + .proc_write_buf = sg_proc_write_adio, };static ssize_t sg_proc_write_dressz (struct file *filp, -const char __user *buffer,size_t count,loff_t *off); +char *buffer,size_t count,loff_t *off);static const struct proc_ops dressz_proc_ops = { .proc_show = sg_proc_seq_show_int, - .proc_write = sg_proc_write_dressz, + .proc_write_buf = sg_proc_write_dressz, };static int sg_proc_seq_show_version (struct seq_file *s,void *v);
@@ -2360,7 +2360,7 @@ static int sg_proc_seq_show_int(struct seq_file *s, void *v) }static ssize_t -sg_proc_write_adio (struct file *filp,const char __user *buffer, +sg_proc_write_adio (struct file *filp,char *buffer,size_t count,loff_t *off) {int err;
@@ -2368,7 +2368,7 @@ sg_proc_write_adio(struct file *filp, const char __user *buffer,if (!capable (CAP_SYS_ADMIN ) || !capable (CAP_SYS_RAWIO ))return -EACCES ; - err =kstrtoul_from_user (buffer, count,0 , &num); + err =kstrtoul (buffer,0 , &num);if (err)return err; sg_allow_dio = num ?1 :0 ;
@@ -2376,7 +2376,7 @@ sg_proc_write_adio(struct file *filp, const char __user *buffer, }static ssize_t -sg_proc_write_dressz (struct file *filp,const char __user *buffer, +sg_proc_write_dressz (struct file *filp,char *buffer,size_t count,loff_t *off) {int err;
@@ -2385,7 +2385,7 @@ sg_proc_write_dressz(struct file *filp, const char __user *buffer,if (!capable (CAP_SYS_ADMIN ) || !capable (CAP_SYS_RAWIO ))return -EACCES ; - err =kstrtoul_from_user (buffer, count,0 , &k); + err =kstrtoul (buffer,0 , &k);if (err)return err;if (k <=1048576 ) {/* limit "big buff" to 1 MB */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 14/26] scsi: sg: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Implement ->proc_write_buf() for
allow_dioanddef_reserved_sizeso procfs copies in what is written before it pins the entry, and parse the number from that copy.
kstrtoul_from_user()looked at the first 66 bytes of whatever was written. Now the whole write is parsed, and anything larger thanPAGE_SIZE- 1 bytes fails with-EINVALfrom procfs before the capability check.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
Christian Brauner
maintainerPATCH RESEND v2 15/26 scsi: esas2r: let procfs copy the ioctl argument of the ATTONode file
In reply to Christian BraunerMove the work of esas2r_ioctl_handler() into esas2r_ioctl_buf() which works on a kernel copy of struct atto_express_ioctl. The SCSI ioctl and the character device keep copying in and out in esas2r_ioctl_handler().
The procfs file implements ->proc_ioctl_buf() with esas2r_ioctl_buf() and lists every command from EXPRESS_IOCTL_MIN to EXPRESS_IOCTL_MAX, so procfs copies the struct in before it pins the entry and back out after unpinning it. Commands outside of that range fail with -ENOTTY instead of -ENOTSUPP now, a NULL argument with -EFAULT.
--- drivers/scsi/esas2r/esas2r.h | 2 ++ drivers/scsi/esas2r/esas2r_ioctl.c | 58 ++++++++++++++++++++++---------------- drivers/scsi/esas2r/esas2r_main.c | 44 +++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 32 deletions(-)
drivers/scsi/esas2r/esas2r.h +2 -0
@@ -964,6 +964,8 @@ struct esas2r_adapter {const char *esas2r_info (struct Scsi_Host *);int esas2r_write_params (struct esas2r_adapter *a,struct esas2r_request *rq,struct esas2r_sas_nvram *data); +int esas2r_ioctl_buf (void *hostdata,unsigned int cmd, +struct atto_express_ioctl *ioctl);int esas2r_ioctl_handler (void *hostdata,unsigned int cmd,void __user *arg);int esas2r_ioctl (struct scsi_device *dev,unsigned int cmd,void __user *arg); u8 handle_hba_ioctl(struct esas2r_adapter *a,
drivers/scsi/esas2r/esas2r_ioctl.c +34 -24
104 lines not on this page · raw message
drivers/scsi/esas2r/esas2r_main.c +36 -8
56 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 15/26] scsi: esas2r: let procfs copy the ioctl argument of the ATTONode file
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] scsi: esas2r: split declaration and initialization of __free() variable in esas2r_ioctl_handler() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] scsi: esas2r: split declaration and initialization of __free() variable in esas2r_ioctl_handler() --
commit 6197b49c6d17310202283a54ea188828c65f914a
Author: Christian Brauner <[email protected]>
scsi: esas2r: let procfs copy the ioctl argument of the ATTONode file
This commit factors the core ATTO ioctl handling out of esas2r_ioctl_handler() into esas2r_ioctl_buf() and wires up the procfs entry to use proc_ioctl_buf with a table of supported commands so procfs handles copying the ioctl buffer to and from userspace.
Quoted 4 lines
drivers/scsi/esas2r/esas2r_ioctl.c +0
-0
[ ... ]
Quoted 10 lines
drivers/scsi/esas2r/esas2r_ioctl.c +6
-0@@ -1516,19 +1502,43 @@ int esas2r_ioctl_handler(void *hostdata, unsigned int cmd, void __user *arg) } +return 0 ; +} + +int esas2r_ioctl_handler (void *hostdata,unsigned int cmd,void __user *arg) +{ + struct atto_express_ioctl *ioctl __free(kfree) = NULL;
drivers/scsi/esas2r/esas2r_ioctl.c int esas2r_ioctl_handler(void *hostdata, unsigned int cmd, void __user *arg) · line 1520
Quoted 10 lines
drivers/scsi/esas2r/esas2r_ioctl.c +10
-0+int err; + +esas2r_log (ESAS2R_LOG_DEBG ,"ioctl (%p, %x, %p)" , hostdata, cmd, arg); + +if ((arg ==NULL ) + || (cmd <EXPRESS_IOCTL_MIN ) + || (cmd >EXPRESS_IOCTL_MAX )) +return -ENOTSUPP ; + + ioctl =memdup_user (arg,sizeof (struct atto_express_ioctl ));
[Severity: Low]
As reported by Sashiko on RFC [1], this isn't a bug, but in esas2r_ioctl_handler() in drivers/scsi/esas2r/esas2r_ioctl.c, the ioctl pointer is declared with __free(kfree) = NULL at the top of the function and then assigned via memdup_user() after the early validation check.
Per the cleanup.h conventions, could ioctl be defined and initialized in a single statement at the memdup_user() call site instead of declaring it at the top of the function?
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Christian Brauner
maintainerPATCH RESEND v2 16/26 hwmon: (dell-smm) let procfs copy the i8k ioctl arguments
In reply to Christian BraunerImplement ->proc_ioctl_buf() so procfs copies the arguments in before it pins the entry and back out after unpinning it. The command numbers in <uapi/linux/i8k.h> encode the wrong sizes, so the table lists what is really copied: an int or the 16 bytes of the machine id out, and one or two ints in.
A NULL argument fails with -EFAULT now instead of -EINVAL, and so does a bad pointer to SET_FAN from an unprivileged task, which got -EPERM before, since procfs copies the argument in before the entry's own checks run. 32-bit tasks can use the commands whose numbers don't depend on the size of size_t.
--- drivers/hwmon/dell-smm-hwmon.c | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +24 -24
@@ -549,16 +549,13 @@ static int i8k_get_power_status(const struct dell_smm_data *data)* Procfs interface */ -static long i8k_ioctl (struct file *fp,unsigned int cmd,unsigned long arg) +static long i8k_ioctl (struct file *fp,unsigned int cmd,void *arg) {struct dell_smm_data *data =pde_data (file_inode (fp)); -int __user *argp = (int __user *)arg; +int *argp = arg;int speed, err;int val =0 ; -if (!argp) -return -EINVAL ; -switch (cmd) {case I8K_BIOS_VERSION : if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
@@ -568,17 +565,13 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) val = (data->bios_version[0 ] <<16 ) | (data->bios_version[1 ] <<8 ) | data->bios_version[2 ]; -if (copy_to_user (argp, &val,sizeof (val))) -return -EFAULT ; - + *argp = val;return 0 ;case I8K_MACHINE_ID :if (restricted && !capable (CAP_SYS_ADMIN ))return -EPERM ; -if (copy_to_user (argp, data->bios_machineid,sizeof (data->bios_machineid))) -return -EFAULT ; - +memcpy (argp, data->bios_machineid,sizeof (data->bios_machineid));return 0 ;case I8K_FN_STATUS : val =i8k_get_fn_status (data);
@@ -593,8 +586,7 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)break ;case I8K_GET_SPEED : -if (copy_from_user (&val, argp,sizeof (int ))) -return -EFAULT ; + val = *argp;if (val >U8_MAX || val <0 )return -EINVAL ;
@@ -603,8 +595,7 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)break ;case I8K_GET_FAN : -if (copy_from_user (&val, argp,sizeof (int ))) -return -EFAULT ; + val = *argp;if (val >U8_MAX || val <0 )return -EINVAL ;
@@ -616,14 +607,11 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)if (restricted && !capable (CAP_SYS_ADMIN ))return -EPERM ; -if (copy_from_user (&val, argp,sizeof (int ))) -return -EFAULT ; - + val = argp[0 ];if (val >U8_MAX || val <0 )return -EINVAL ; -if (copy_from_user (&speed, argp +1 ,sizeof (int ))) -return -EFAULT ; + speed = argp[1 ]; speed =clamp_val (speed,0 , data->i8k_fan_max);
@@ -643,12 +631,22 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)if (val <0 )return val; -if (copy_to_user (argp, &val,sizeof (int ))) -return -EFAULT ; - + *argp = val;return 0 ; } +/* The command numbers don't encode what is copied, see <uapi/linux/i8k.h>. */ +static const struct proc_ioctl_arg i8k_ioctl_args[] = { +PROC_IOCTL_ARG (I8K_BIOS_VERSION ,0 ,sizeof (int )), + PROC_IOCTL_ARG(I8K_MACHINE_ID, 0, sizeof_field(struct dell_smm_data, bios_machineid)), +PROC_IOCTL_ARG (I8K_FN_STATUS ,0 ,sizeof (int )), +PROC_IOCTL_ARG (I8K_POWER_STATUS ,0 ,sizeof (int )), +PROC_IOCTL_ARG (I8K_GET_TEMP ,0 ,sizeof (int )), +PROC_IOCTL_ARG (I8K_GET_SPEED ,sizeof (int ),sizeof (int )), +PROC_IOCTL_ARG (I8K_GET_FAN ,sizeof (int ),sizeof (int )), +PROC_IOCTL_ARG (I8K_SET_FAN ,2 *sizeof (int ),sizeof (int )), +}; +/* * Print the information for /proc/i8k. */
@@ -696,7 +694,9 @@ static int i8k_proc_show(struct seq_file *seq, void *offset)static const struct proc_ops i8k_proc_ops = { .proc_show = i8k_proc_show, - .proc_ioctl = i8k_ioctl, + .proc_ioctl_buf = i8k_ioctl, + .proc_ioctl_args = i8k_ioctl_args, + .proc_nr_ioctl_args =ARRAY_SIZE (i8k_ioctl_args), };static void i8k_exit_procfs (void *param)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 16/26] hwmon: (dell-smm) let procfs copy the i8k ioctl arguments
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_ioctl_buf() so procfs copies the arguments in before it pins the entry and back out after unpinning it. The command numbers in <
uapi/linux/i8k.h> encode the wrong sizes, so the table lists what is really copied: an int or the 16 bytes of the machine id out, and one or two ints in.
Quoted 7 lines
A NULL argument fails with
-EFAULTnow instead of-EINVAL, and so does a bad pointer toSET_FANfrom an unprivileged task, which got-EPERMbefore, since procfs copies the argument in before the entry's own checks run. 32-bit tasks can use the commands whose numbers don't depend on the size ofsize_t.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Christian Brauner
maintainerPATCH RESEND v2 17/26 fbdev: viafb: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for the files in /proc/viafb so procfs copies in what is written before it pins the entry, and parse what was written from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now, the output device files refused anything over 63 bytes already. kstrtou8_from_user() looked at the first 10 bytes of what was written to dfph and dfpl, now the whole write is parsed.
--- drivers/video/fbdev/via/viafbdev.c | 46 +++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-)
drivers/video/fbdev/via/viafbdev.c +21 -25
@@ -1121,7 +1121,7 @@ static int viafb_dvp0_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_dvp0_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {char buf[20 ], *value, *pbuf;u8 reg_val =0 ;
@@ -1129,8 +1129,7 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,if (count <1 )return -EINVAL ; length = count >20 ?20 : count; -if (copy_from_user (&buf[0 ], buffer, length)) -return -EFAULT ; +memcpy (&buf[0 ], buffer, length); buf[length -1 ] ='\0' ;/*Ensure end string */ pbuf = &buf[0 ];for (i =0 ; i <3 ; i++) {
@@ -1169,7 +1168,7 @@ static ssize_t viafb_dvp0_proc_write(struct file *file,static const struct proc_ops viafb_dvp0_proc_ops = { .proc_show = viafb_dvp0_proc_show, - .proc_write = viafb_dvp0_proc_write, + .proc_write_buf = viafb_dvp0_proc_write, };static int viafb_dvp1_proc_show (struct seq_file *m,void *v)
@@ -1183,7 +1182,7 @@ static int viafb_dvp1_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_dvp1_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {char buf[20 ], *value, *pbuf;u8 reg_val =0 ;
@@ -1191,8 +1190,7 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,if (count <1 )return -EINVAL ; length = count >20 ?20 : count; -if (copy_from_user (&buf[0 ], buffer, length)) -return -EFAULT ; +memcpy (&buf[0 ], buffer, length); buf[length -1 ] ='\0' ;/*Ensure end string */ pbuf = &buf[0 ];for (i =0 ; i <3 ; i++) {
@@ -1225,7 +1223,7 @@ static ssize_t viafb_dvp1_proc_write(struct file *file,static const struct proc_ops viafb_dvp1_proc_ops = { .proc_show = viafb_dvp1_proc_show, - .proc_write = viafb_dvp1_proc_write, + .proc_write_buf = viafb_dvp1_proc_write, };static int viafb_dfph_proc_show (struct seq_file *m,void *v)
@@ -1237,11 +1235,11 @@ static int viafb_dfph_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_dfph_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {int err;u8 reg_val; - err =kstrtou8_from_user (buffer, count,0 , ®_val); + err =kstrtou8 (buffer,0 , ®_val);if (err)return err;
@@ -1251,7 +1249,7 @@ static ssize_t viafb_dfph_proc_write(struct file *file,static const struct proc_ops viafb_dfph_proc_ops = { .proc_show = viafb_dfph_proc_show, - .proc_write = viafb_dfph_proc_write, + .proc_write_buf = viafb_dfph_proc_write, };static int viafb_dfpl_proc_show (struct seq_file *m,void *v)
@@ -1263,11 +1261,11 @@ static int viafb_dfpl_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_dfpl_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {int err;u8 reg_val; - err =kstrtou8_from_user (buffer, count,0 , ®_val); + err =kstrtou8 (buffer,0 , ®_val);if (err)return err;
@@ -1277,7 +1275,7 @@ static ssize_t viafb_dfpl_proc_write(struct file *file,static const struct proc_ops viafb_dfpl_proc_ops = { .proc_show = viafb_dfpl_proc_show, - .proc_write = viafb_dfpl_proc_write, + .proc_write_buf = viafb_dfpl_proc_write, };static int viafb_vt1636_proc_show (struct seq_file *m,void *v)
@@ -1313,7 +1311,7 @@ static int viafb_vt1636_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_vt1636_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {char buf[30 ], *value, *pbuf;struct IODATA reg_val;
@@ -1321,8 +1319,7 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,if (count <1 )return -EINVAL ; length = count >30 ?30 : count; -if (copy_from_user (&buf[0 ], buffer, length)) -return -EFAULT ; +memcpy (&buf[0 ], buffer, length); buf[length -1 ] ='\0' ;/*Ensure end string */ pbuf = &buf[0 ];switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
@@ -1404,7 +1401,7 @@ static ssize_t viafb_vt1636_proc_write(struct file *file,static const struct proc_ops viafb_vt1636_proc_ops = { .proc_show = viafb_vt1636_proc_show, - .proc_write = viafb_vt1636_proc_write, + .proc_write_buf = viafb_vt1636_proc_write, };#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
@@ -1416,7 +1413,7 @@ static int __maybe_unused viafb_sup_odev_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t odev_update (const char __user *buffer,size_t count,u32 *odev) +static ssize_t odev_update (const char *buffer,size_t count,u32 *odev) {char buf[64 ], *ptr = buf;u32 devices;
@@ -1424,8 +1421,7 @@ static ssize_t odev_update(const char __user *buffer, size_t count, u32 *odev)if (count <1 || count >63 )return -EINVAL ; -if (copy_from_user (&buf[0 ], buffer, count)) -return -EFAULT ; +memcpy (&buf[0 ], buffer, count); buf[count] ='\0' ; add = buf[0 ] =='+' ; sub = buf[0 ] =='-' ;
@@ -1452,7 +1448,7 @@ static int viafb_iga1_odev_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_iga1_odev_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {u32 dev_on, dev_off, dev_old, dev_new;ssize_t res;
@@ -1473,7 +1469,7 @@ static ssize_t viafb_iga1_odev_proc_write(struct file *file,static const struct proc_ops viafb_iga1_odev_proc_ops = { .proc_show = viafb_iga1_odev_proc_show, - .proc_write = viafb_iga1_odev_proc_write, + .proc_write_buf = viafb_iga1_odev_proc_write, };static int viafb_iga2_odev_proc_show (struct seq_file *m,void *v)
@@ -1483,7 +1479,7 @@ static int viafb_iga2_odev_proc_show(struct seq_file *m, void *v) }static ssize_t viafb_iga2_odev_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {u32 dev_on, dev_off, dev_old, dev_new;ssize_t res;
@@ -1504,7 +1500,7 @@ static ssize_t viafb_iga2_odev_proc_write(struct file *file,static const struct proc_ops viafb_iga2_odev_proc_ops = { .proc_show = viafb_iga2_odev_proc_show, - .proc_write = viafb_iga2_odev_proc_write, + .proc_write_buf = viafb_iga2_odev_proc_write, };#define IS_VT1636 (lvds_chip) ((lvds_chip).lvds_chip_name == VT1636_LVDS)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 17/26] fbdev: viafb: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Implement ->proc_write_buf() for the files in
/proc/viafbso procfs copies in what is written before it pins the entry, and parse what was written from that copy. Writes larger thanPAGE_SIZE- 1 bytes fail with-EINVALnow, the output device files refused anything over 63 bytes already.kstrtou8_from_user()looked at the first 10 bytes of what was written to dfph and dfpl, now the whole write is parsed.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Christian Brauner
maintainerPATCH RESEND v2 18/26 usb: gadget: function: rndis: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to /proc/driver/rndis-<n> before it pins the entry, and handle the commands from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- drivers/usb/gadget/function/rndis.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/gadget/function/rndis.c +4 -5
@@ -1138,7 +1138,7 @@ static int rndis_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t rndis_proc_write (struct file *file,const char __user *buffer, +static ssize_t rndis_proc_write (struct file *file,char *buffer,size_t count,loff_t *ppos) {rndis_params *p =pde_data (file_inode (file));
@@ -1146,9 +1146,8 @@ static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,int i, fl_speed =0 ;for (i =0 ; i < count; i++) { -char c; -if (get_user (c, buffer)) -return -EFAULT ; +char c = *buffer; +switch (c) {case '0' :case '1' :
@@ -1185,7 +1184,7 @@ static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,static const struct proc_ops rndis_proc_ops = { .proc_show = rndis_proc_show, - .proc_write = rndis_proc_write, + .proc_write_buf = rndis_proc_write, };#define NAME_TEMPLATE "driver/rndis-%03d"
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 18/26] usb: gadget: function: rndis: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_write_buf() so procfs copies in what is written to /proc/driver/rndis-<n> before it pins the entry, and handle the commands from that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
Christian Brauner
maintainerPATCH RESEND v2 19/26 wifi: ipw2x00: let procfs copy in writes to the debug level
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and parse the level from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now, and a buffer that can't be read fails with -EFAULT instead of looking like it was written.
--- drivers/net/wireless/intel/ipw2x00/libipw_module.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/wireless/intel/ipw2x00/libipw_module.c +3 -4
@@ -216,14 +216,13 @@ static int debug_level_proc_show(struct seq_file *m, void *v) } static ssize_t debug_level_proc_write(struct file *file, - const char __user *buffer, size_t count, loff_t *pos) + char *buffer, size_t count, loff_t *pos) { char buf[] = "0x00000000\n"; size_t len = min(sizeof(buf) - 1, count); unsigned long val; - if (copy_from_user(buf, buffer, len)) - return count; + memcpy(buf, buffer, len); buf[len] = 0; if (sscanf(buf, "%li", &val) != 1) printk(KERN_INFO DRV_NAME
@@ -236,7 +235,7 @@ static ssize_t debug_level_proc_write(struct file *file,static const struct proc_ops debug_level_proc_ops = { .proc_show = debug_level_proc_show, - .proc_write = debug_level_proc_write, + .proc_write_buf = debug_level_proc_write, };#endif /* CONFIG_LIBIPW_DEBUG */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 19/26] wifi: ipw2x00: let procfs copy in writes to the debug level
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and parse the level from that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow, and a buffer that can't be read fails with-EFAULTinstead of looking like it was written.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
Christian Brauner
maintainerPATCH RESEND v2 20/26 tty: sysrq: let procfs copy in writes to /proc/sysrq-trigger
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and handle the keys from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now. They used to trigger the first key, or all of them in bulk mode. procfs allocates the copy, which is as small as the write, opening the file allocated as much already.
--- drivers/tty/sysrq.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/tty/sysrq.c +3 -6
@@ -1200,17 +1200,14 @@ EXPORT_SYMBOL(unregister_sysrq_key);* However, if the first character is an underscore, * all characters are processed. */ -static ssize_t write_sysrq_trigger (struct file *file,const char __user *buf, +static ssize_t write_sysrq_trigger (struct file *file,char *buf,size_t count,loff_t *ppos) {bool bulk = false;size_t i;for (i =0 ; i < count; i++) { -char c; - -if (get_user (c, buf + i)) -return -EFAULT ; +char c = buf[i];if (c =='_' ) bulk = true;
@@ -1225,7 +1222,7 @@ static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf, }static const struct proc_ops sysrq_trigger_proc_ops = { - .proc_write = write_sysrq_trigger, + .proc_write_buf = write_sysrq_trigger, .proc_lseek = noop_llseek, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 20/26] tty: sysrq: let procfs copy in writes to /proc/sysrq-trigger
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and handle the keys from that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow. They used to trigger the first key, or all of them in bulk mode. procfs allocates the copy, which is as small as the write, opening the file allocated as much already.Reviewed-by Jiri Slaby <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
Christian Brauner
maintainerPATCH RESEND v2 21/26 Input: let procfs own the wait queue of /proc/bus/input/devices
In reply to Christian Braunerinput_proc_devices_poll() sleeps the poller on a queue of its own. procfs owns the queue poll() uses now, so leave the poll_wait() to it and wake its pollers instead.
--- drivers/input/input.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/input/input.c +7 -6
@@ -1082,13 +1082,13 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han#ifdef CONFIG_PROC_FS static struct proc_dir_entry *proc_bus_input_dir; -static DECLARE_WAIT_QUEUE_HEAD (input_devices_poll_wait); +static struct proc_dir_entry *proc_bus_input_devices;static int input_devices_state;static inline void input_wakeup_procfs_readers (void ) { input_devices_state++; -wake_up (&input_devices_poll_wait); +proc_poll_notify (proc_bus_input_devices); } struct input_seq_state {
@@ -1102,7 +1102,6 @@ static __poll_t input_proc_devices_poll(struct file *file, poll_table *wait)struct seq_file *seq = file->private_data;struct input_seq_state *state = seq->private; -poll_wait (file, &input_devices_poll_wait, wait);if (state->input_devices_state != input_devices_state) { state->input_devices_state = input_devices_state;return EPOLLIN |EPOLLRDNORM ;
@@ -1284,9 +1283,9 @@ static int __init input_proc_init(void)if (!proc_bus_input_dir)return -ENOMEM ; - entry =proc_create ("devices" ,0 , proc_bus_input_dir, - &input_devices_proc_ops); -if (!entry) + proc_bus_input_devices =proc_create ("devices" ,0 , proc_bus_input_dir, + &input_devices_proc_ops); +if (!proc_bus_input_devices) goto fail1; entry = proc_create("handlers", 0, proc_bus_input_dir,
@@ -1297,6 +1296,7 @@ static int __init input_proc_init(void)return 0 ; fail2:remove_proc_entry ("devices" , proc_bus_input_dir); + proc_bus_input_devices =NULL ; fail1:remove_proc_entry ("bus/input" ,NULL );return -ENOMEM ; }
@@ -1304,6 +1304,7 @@ static int __init input_proc_init(void)static void input_proc_exit (void ) {remove_proc_entry ("devices" , proc_bus_input_dir); + proc_bus_input_devices =NULL ;remove_proc_entry ("handlers" , proc_bus_input_dir);remove_proc_entry ("bus/input" ,NULL ); }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 21/26] Input: let procfs own the wait queue of /proc/bus/input/devices
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
input_proc_devices_poll()sleeps the poller on a queue of its own. procfs owns the queuepoll()uses now, so leave thepoll_wait()to it and wake its pollers instead.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Christian Brauner
maintainerPATCH RESEND v2 22/26 ALSA: info: let procfs own the seq_file of text entries
In reply to Christian BraunerDeclare the show function and let procfs open and free the seq_file. ->proc_open() only sets up the private data and preallocates the buffer now and ->proc_release() no longer releases the seq_file. Reading an entry then no longer holds up its removal when the card goes away.
--- sound/core/info.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
sound/core/info.c +9 -10
@@ -346,9 +346,11 @@ static int snd_info_seq_show(struct seq_file *seq, void *p)return 0 ; } +/* procfs opens the seq_file */ static int snd_info_text_entry_open (struct inode *inode,struct file *file) {struct snd_info_entry *entry =pde_data (inode); +struct seq_file *m = file->private_data;struct snd_info_private_data *data;int err;
@@ -362,13 +364,12 @@ static int snd_info_text_entry_open(struct inode *inode, struct file *file) err = -ENOMEM ; goto error; } -if (entry->size) - err =single_open_size (file, snd_info_seq_show, data, - entry->size); -else - err =single_open (file, snd_info_seq_show, data); -if (err <0 ) - goto error; +if (entry->size) { + err =seq_preallocate (m, entry->size); +if (err <0 ) + goto error; + } + m->private = data;return 0 ; error:
@@ -387,7 +388,6 @@ static int snd_info_text_entry_release(struct inode *inode, struct file *file)if (data->wbuffer && entry->c.text.write) entry->c.text.write (entry, data->wbuffer); -single_release (inode, file);kfree (data->rbuffer);if (data->wbuffer) {kvfree (data->wbuffer->buffer);
@@ -401,11 +401,10 @@ static int snd_info_text_entry_release(struct inode *inode, struct file *file)static const struct proc_ops snd_info_text_entry_ops = { + .proc_show = snd_info_seq_show, .proc_open = snd_info_text_entry_open, .proc_release = snd_info_text_entry_release, .proc_write = snd_info_text_entry_write, - .proc_lseek = seq_lseek, - .proc_read = seq_read, }; static struct snd_info_entry *create_subdir(struct module *mod,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 22/26] ALSA: info: let procfs own the seq_file of text entries
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Declare the show function and let procfs open and free the
seq_file. ->proc_open() only sets up the private data and preallocates the buffer now and ->proc_release() no longer releases theseq_file. Reading an entry then no longer holds up its removal when the card goes away.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
Re: [PATCH RESEND v2 22/26] ALSA: info: let procfs own the seq_file of text entries
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Declare the show function and let procfs open and free the
seq_file. ->proc_open() only sets up the private data and preallocates the buffer now and ->proc_release() no longer releases theseq_file. Reading an entry then no longer holds up its removal when the card goes away.
[...]
Quoted 15 lines
sound/core/info.c +3
-1+ goto error; + } + m->private = data;return 0 ; error:@@ -387,7 +388,6 @@ static int snd_info_text_entry_release(struct inode *inode, struct file *file)if (data->wbuffer && entry->c.text.write) entry->c.text.write (entry, data->wbuffer); -single_release (inode, file);kfree (data->rbuffer);if (data->wbuffer) {kvfree (data->wbuffer->buffer);
sound/core/info.c static int snd_info_text_entry_release(struct inode *inode, struct file *file) · line 408
Quoted 10 lines
sound/core/info.c +1
-2@@ -401,11 +401,10 @@ static int snd_info_text_entry_release(struct inode *inode, struct file *file)static const struct proc_ops snd_info_text_entry_ops = { + .proc_show = snd_info_seq_show, .proc_open = snd_info_text_entry_open, .proc_release = snd_info_text_entry_release, .proc_write = snd_info_text_entry_write, - .proc_lseek = seq_lseek, - .proc_read = seq_read, };
Is this safe? Looking at the work.procfs.cleanup tree, the proc_release handler (snd_info_text_entry_release()) can call entry->c.text.write(entry, data->wbuffer), and the only kind of reference dropped by snd_info_text_entry_release() is a module reference.
I think the entry could concurrently get freed by snd_info_free_entry()?
Re: [PATCH RESEND v2 22/26] ALSA: info: let procfs own the seq_file of text entries
Quoted 38 lines · Jann Horn
Quoted 4 lines · Christian Brauner
Declare the show function and let procfs open and free the
seq_file. ->proc_open() only sets up the private data and preallocates the buffer now and ->proc_release() no longer releases theseq_file. Reading an entry then no longer holds up its removal when the card goes away.[...]
Quoted 15 lines
sound/core/info.c +3
-1+ goto error; + } + m->private = data;return 0 ; error:@@ -387,7 +388,6 @@ static int snd_info_text_entry_release(struct inode *inode, struct file *file)if (data->wbuffer && entry->c.text.write) entry->c.text.write (entry, data->wbuffer); -single_release (inode, file);kfree (data->rbuffer);if (data->wbuffer) {kvfree (data->wbuffer->buffer);sound/core/info.c static int snd_info_text_entry_release(struct inode *inode, struct file *file) · line 408
Quoted 10 lines
sound/core/info.c +1
-2@@ -401,11 +401,10 @@ static int snd_info_text_entry_release(struct inode *inode, struct file *file)static const struct proc_ops snd_info_text_entry_ops = { + .proc_show = snd_info_seq_show, .proc_open = snd_info_text_entry_open, .proc_release = snd_info_text_entry_release, .proc_write = snd_info_text_entry_write, - .proc_lseek = seq_lseek, - .proc_read = seq_read, };Is this safe? Looking at the work.procfs.cleanup tree, the
proc_releasehandler (snd_info_text_entry_release()) can callentry->c.text.write(entry, data->wbuffer), and the only kind of reference dropped bysnd_info_text_entry_release()is a module reference.
Quoted 1 line
I think the entry could concurrently get freed by
snd_info_free_entry()?
Ah, no, this is fine because ->proc_release still happens at the same time as before.
Sorry for the noise, should've thought a minute more.
Christian Brauner
maintainerPATCH RESEND v2 23/26 ALSA: info: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for data and text entries so procfs copies in what is written before it pins the entry.
Data entries take writes a page at a time with PROC_ENTRY_SHORT_WRITES. They used to get the whole write at once. ->write() of struct snd_info_entry_ops gets the kernel copy and opl4, its only user, writes it to the sample memory without bouncing it through a vmalloc() buffer of its own.
Text entries take up to SND_INFO_TEXT_WRITE_MAX bytes at once like before. A single write that is larger fails with -EINVAL from procfs instead of -EIO now.
--- include/sound/info.h | 2 +- sound/core/info.c | 21 ++++++++++++--------- sound/drivers/opl4/opl4_proc.c | 11 +---------- 3 files changed, 14 insertions(+), 20 deletions(-)
include/sound/info.h +1 -1
@@ -42,7 +42,7 @@ struct snd_info_entry_ops { struct file *file, char __user *buf, size_t count, loff_t pos);ssize_t (*write)(struct snd_info_entry *entry,void *file_private_data, -struct file *file,const char __user *buf, +struct file *file,const char *buf,size_t count,loff_t pos); loff_t (*llseek)(struct snd_info_entry *entry, void *file_private_data, struct file *file,
sound/core/info.c +12 -9
@@ -160,7 +160,7 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,return size; } -static ssize_t snd_info_entry_write (struct file *file,const char __user *buffer, +static ssize_t snd_info_entry_write (struct file *file,char *buffer,size_t count,loff_t * offset) {struct snd_info_private_data *data = file->private_data;
@@ -277,9 +277,11 @@ static int snd_info_entry_release(struct inode *inode, struct file *file)static const struct proc_ops snd_info_entry_operations = { + .proc_flags =PROC_ENTRY_SHORT_WRITES , .proc_lseek = snd_info_entry_llseek, .proc_read = snd_info_entry_read, - .proc_write = snd_info_entry_write, + .proc_write_buf = snd_info_entry_write, + .proc_write_size =PAGE_SIZE , .proc_poll = snd_info_entry_poll, .proc_ioctl = snd_info_entry_ioctl, .proc_mmap = snd_info_entry_mmap,
@@ -287,11 +289,13 @@ static const struct proc_ops snd_info_entry_operations = .proc_release = snd_info_entry_release, }; +/* don't handle too large text inputs */ +#define SND_INFO_TEXT_WRITE_MAX (16 * 1024) +/* * file ops for text proc files */ -static ssize_t snd_info_text_entry_write (struct file *file, -const char __user *buffer, +static ssize_t snd_info_text_entry_write (struct file *file,char *buffer,size_t count,loff_t *offset) {struct seq_file *m = file->private_data;
@@ -307,8 +311,7 @@ static ssize_t snd_info_text_entry_write(struct file *file,if (!valid_pos (pos, count))return -EIO ; next = pos + count; -/* don't handle too large text inputs */ -if (next >16 *1024 ) +if (next >SND_INFO_TEXT_WRITE_MAX )return -EIO ;guard (mutex)(&entry->access); buf = data->wbuffer;
@@ -325,8 +328,7 @@ static ssize_t snd_info_text_entry_write(struct file *file, buf->buffer = nbuf; buf->len =PAGE_ALIGN (next); } -if (copy_from_user (buf->buffer + pos, buffer, count)) -return -EFAULT ; +memcpy (buf->buffer + pos, buffer, count); buf->size = next; *offset = next;return count;
@@ -404,7 +406,8 @@ static const struct proc_ops snd_info_text_entry_ops = .proc_show = snd_info_seq_show, .proc_open = snd_info_text_entry_open, .proc_release = snd_info_text_entry_release, - .proc_write = snd_info_text_entry_write, + .proc_write_buf = snd_info_text_entry_write, + .proc_write_size = SND_INFO_TEXT_WRITE_MAX, }; static struct snd_info_entry *create_subdir(struct module *mod,
sound/drivers/opl4/opl4_proc.c +1 -10
@@ -54,21 +54,12 @@ static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,static ssize_t snd_opl4_mem_proc_write (struct snd_info_entry *entry,void *file_private_data,struct file *file, -const char __user *_buf, +const char *buf,size_t count,loff_t pos) {struct snd_opl4 *opl4 = entry->private_data; -char *buf; - buf =vmalloc (count); -if (!buf) -return -ENOMEM ; -if (copy_from_user (buf, _buf, count)) { -vfree (buf); -return -EFAULT ; - }snd_opl4_write_memory (opl4, buf, pos, count); -vfree (buf);return count; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 23/26] ALSA: info: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Implement ->proc_write_buf() for data and text entries so procfs copies in what is written before it pins the entry.
Data entries take writes a page at a time with
PROC_ENTRY_SHORT_WRITES. They used to get the whole write at once. ->write() of structsnd_info_entry_opsgets the kernel copy and opl4, its only user, writes it to the sample memory without bouncing it through avmalloc()buffer of its own.
Quoted 5 lines
Text entries take up to
SND_INFO_TEXT_WRITE_MAXbytes at once like before. A single write that is larger fails with-EINVALfrom procfs instead of-EIOnow.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
Christian Brauner
maintainerPATCH RESEND v2 24/26 ALSA: info: let procfs copy out reads of data entries
In reply to Christian BraunerImplement ->proc_read_buf() for data entries so procfs copies what is read to userspace after it unpinned the entry. ->read() of struct snd_info_entry_ops fills procfs' buffer now. opl4 reads the sample memory into it without a vmalloc() buffer of its own, gus, cs46xx, emu10k1, scarlett2, cs4281 and mixart copy into it instead of to userspace. The driver guide still told raw callbacks to copy to and from userspace, so update its example as well. Data entries ask for PROC_ENTRY_FULL_READS so that reading all of an entry at once keeps working. A read that faults on its buffer in a later piece returns the pieces before it now instead of failing with -EFAULT.
Unbinding a card then no longer waits for a reader that faults on its buffer.
--- Documentation/sound/kernel-api/writing-an-alsa-driver.rst | 10 +++++----- include/sound/gus.h | 2 +- include/sound/info.h | 2 +- sound/core/info.c | 6 +++--- sound/drivers/opl4/opl4_proc.c | 12 +----------- sound/isa/gus/gus_dram.c | 7 +++---- sound/isa/gus/gus_mem_proc.c | 2 +- sound/pci/cs4281.c | 10 ++++------ sound/pci/cs46xx/cs46xx_lib.c | 5 ++--- sound/pci/emu10k1/emuproc.c | 8 +++----- sound/pci/mixart/mixart.c | 10 ++++------ sound/usb/mixer_scarlett2.c | 9 ++++----- 12 files changed, 32 insertions(+), 51 deletions(-)
Documentation/sound/kernel-api/writing-an-alsa-driver.rst +5 -5
@@ -3679,9 +3679,10 @@ For raw data, ``size`` field must be set properly. This specifies the maximum size of the proc file access. The read/write callbacks of raw mode are more direct than the text mode. -You need to use a low-level I/O functions such as -:c:func:`copy_from_user()` and :c:func:`copy_to_user()` to transfer the -data:: +They get a kernel buffer that procfs copies to or from userspace, so they +just copy the data. The buffer holds at most a page and isn't zeroed, so +a read callback must return exactly what it copied into it; a larger +read comes back for the rest:: static ssize_t my_file_io_read(struct snd_info_entry *entry, void *file_private_data,
@@ -3690,8 +3691,7 @@ data:: size_t count, loff_t pos) { - if (copy_to_user(buf, local_data + pos, count)) - return -EFAULT; + memcpy(buf, local_data + pos, count); return count; }
include/sound/gus.h +1 -1
@@ -594,7 +594,7 @@ void snd_gf1_uart_resume(struct snd_gus_card *gus);/* gus_dram.c */ int snd_gus_dram_write (struct snd_gus_card *gus,char __user *ptr,unsigned int addr,unsigned int size); -int snd_gus_dram_read (struct snd_gus_card *gus,char __user *ptr, +int snd_gus_dram_read (struct snd_gus_card *gus,char *ptr,unsigned int addr,unsigned int size,int rom);/* gus_timer.c */
include/sound/info.h +1 -1
@@ -39,7 +39,7 @@ struct snd_info_entry_ops {int (*release)(struct snd_info_entry *entry,unsigned short mode,void *file_private_data);ssize_t (*read)(struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos); ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data, struct file *file, const char *buf,
sound/core/info.c +3 -3
@@ -138,7 +138,7 @@ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)return offset; } -static ssize_t snd_info_entry_read (struct file *file,char __user *buffer, +static ssize_t snd_info_entry_read (struct file *file,char *buffer,size_t count,loff_t * offset) {struct snd_info_private_data *data = file->private_data;
@@ -277,9 +277,9 @@ static int snd_info_entry_release(struct inode *inode, struct file *file)static const struct proc_ops snd_info_entry_operations = { - .proc_flags =PROC_ENTRY_SHORT_WRITES , + .proc_flags =PROC_ENTRY_SHORT_WRITES |PROC_ENTRY_FULL_READS , .proc_lseek = snd_info_entry_llseek, - .proc_read = snd_info_entry_read, + .proc_read_buf = snd_info_entry_read, .proc_write_buf = snd_info_entry_write, .proc_write_size =PAGE_SIZE , .proc_poll = snd_info_entry_poll,
sound/drivers/opl4/opl4_proc.c +1 -11
@@ -5,7 +5,6 @@*/ #include "opl4_local.h" -#include <linux/vmalloc.h> #include <linux/export.h> #include <sound/info.h>
@@ -33,21 +32,12 @@ static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,static ssize_t snd_opl4_mem_proc_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *_buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct snd_opl4 *opl4 = entry->private_data; -char * buf; - buf =vmalloc (count); -if (!buf) -return -ENOMEM ;snd_opl4_read_memory (opl4, buf, pos, count); -if (copy_to_user (_buf, buf, count)) { -vfree (buf); -return -EFAULT ; - } -vfree (buf);return count; }
sound/isa/gus/gus_dram.c +3 -4
@@ -45,7 +45,7 @@ int snd_gus_dram_write(struct snd_gus_card *gus, char __user *buffer,return snd_gus_dram_poke (gus, buffer, address, size); } -static int snd_gus_dram_peek (struct snd_gus_card *gus,char __user *_buffer, +static int snd_gus_dram_peek (struct snd_gus_card *gus,char *_buffer,unsigned int address,unsigned int size,int rom) {
@@ -67,15 +67,14 @@ static int snd_gus_dram_peek(struct snd_gus_card *gus, char __user *_buffer,while (size2--) *pbuffer++ =snd_gf1_peek (gus, address++); } -if (copy_to_user (_buffer, buffer, size1)) -return -EFAULT ; +memcpy (_buffer, buffer, size1); size -= size1; _buffer += size1; }return 0 ; } -int snd_gus_dram_read (struct snd_gus_card *gus,char __user *buffer, +int snd_gus_dram_read (struct snd_gus_card *gus,char *buffer,unsigned int address,unsigned int size,int rom) {
sound/isa/gus/gus_mem_proc.c +1 -1
@@ -18,7 +18,7 @@ struct gus_proc_private {static ssize_t snd_gf1_mem_proc_dump (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct gus_proc_private *priv = entry->private_data;
sound/pci/cs4281.c +4 -6
@@ -1104,25 +1104,23 @@ static void snd_cs4281_proc_read(struct snd_info_entry *entry,static ssize_t snd_cs4281_BA0_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct cs4281 *chip = entry->private_data; -if (copy_to_user_fromio (buf, chip->ba0 + pos, count)) -return -EFAULT ; +memcpy_fromio (buf, chip->ba0 + pos, count);return count; }static ssize_t snd_cs4281_BA1_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct cs4281 *chip = entry->private_data; -if (copy_to_user_fromio (buf, chip->ba1 + pos, count)) -return -EFAULT ; +memcpy_fromio (buf, chip->ba1 + pos, count);return count; }
sound/pci/cs46xx/cs46xx_lib.c +2 -3
@@ -2741,13 +2741,12 @@ static inline void snd_cs46xx_remove_gameport(struct snd_cs46xx *chip) { }static ssize_t snd_cs46xx_io_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct snd_cs46xx_region *region = entry->private_data; -if (copy_to_user_fromio (buf, region->remap_addr + pos, count)) -return -EFAULT ; +memcpy_fromio (buf, region->remap_addr + pos, count);return count; }
sound/pci/emu10k1/emuproc.c +3 -5
@@ -382,7 +382,7 @@ static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry,static ssize_t snd_emu10k1_fx8010_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct snd_emu10k1 *emu = entry->private_data;
@@ -415,10 +415,8 @@ static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry, } tmp[idx] = val; } -if (copy_to_user (buf, ((char *)tmp) + (pos &3 ), count)) - res = -EFAULT ; -else - res = count; +memcpy (buf, ((char *)tmp) + (pos &3 ), count); + res = count;kfree (tmp);return res; }
sound/pci/mixart/mixart.c +4 -6
@@ -1110,14 +1110,13 @@ static int snd_mixart_free(struct mixart_mgr *mgr)*/ static ssize_t snd_mixart_BA0_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct mixart_mgr *mgr = entry->private_data; count = count & ~3 ;/* make sure the read size is a multiple of 4 bytes */ -if (copy_to_user_fromio (buf,MIXART_MEM (mgr, pos), count)) -return -EFAULT ; +memcpy_fromio (buf,MIXART_MEM (mgr, pos), count);return count; }
@@ -1126,14 +1125,13 @@ static ssize_t snd_mixart_BA0_read(struct snd_info_entry *entry,*/ static ssize_t snd_mixart_BA1_read (struct snd_info_entry *entry,void *file_private_data, -struct file *file,char __user *buf, +struct file *file,char *buf,size_t count,loff_t pos) {struct mixart_mgr *mgr = entry->private_data; count = count & ~3 ;/* make sure the read size is a multiple of 4 bytes */ -if (copy_to_user_fromio (buf,MIXART_REG (mgr, pos), count)) -return -EFAULT ; +memcpy_fromio (buf,MIXART_REG (mgr, pos), count);return count; }
sound/usb/mixer_scarlett2.c +4 -5
@@ -9763,7 +9763,7 @@ static ssize_t scarlett2_devmap_read(struct snd_info_entry *entry, void *file_private_data, struct file *file, - char __user *buf, + char *buf, size_t count, loff_t pos) {
@@ -9785,7 +9785,7 @@ static ssize_t scarlett2_devmap_read(while (count >0 ) {/* SCARLETT2_USB_GET_DEVMAP reads only on block boundaries, * so we need to read a whole block and copy the requested -* chunk to userspace. +* chunk out of it. */ __le32 req;
@@ -9800,7 +9800,7 @@ static ssize_t scarlett2_devmap_read( block_size, entry->size - block_start); -/* size of the chunk to copy to userspace */ +/* size of the chunk to copy out of the block */ size_t copy_size =min_t (size_t, count, read_size - offset);/* request the block */
@@ -9810,8 +9810,7 @@ static ssize_t scarlett2_devmap_read(if (err <0 )return copied ? copied : err; -if (copy_to_user (buf, resp_buf + offset, copy_size)) -return -EFAULT ; +memcpy (buf, resp_buf + offset, copy_size); buf += copy_size; pos += copy_size;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 24/26] ALSA: info: let procfs copy out reads of data entries
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Implement ->proc_read_buf() for data entries so procfs copies what is read to userspace after it unpinned the entry. ->read() of struct
snd_info_entry_opsfills procfs' buffer now. opl4 reads the sample memory into it without avmalloc()buffer of its own, gus, cs46xx, emu10k1, scarlett2, cs4281 and mixart copy into it instead of to userspace. The driver guide still told raw callbacks to copy to and from userspace, so update its example as well. Data entries ask forPROC_ENTRY_FULL_READSso that reading all of an entry at once keeps working. A read that faults on its buffer in a later piece returns the pieces before it now instead of failing with-EFAULT.
Quoted 4 lines
Unbinding a card then no longer waits for a reader that faults on its buffer.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
Christian Brauner
maintainerPATCH RESEND v2 25/26 ALSA: info: drop the ioctl hook of data entries
In reply to Christian BraunerNo driver implements ->ioctl() of struct snd_info_entry_ops.
--- include/sound/info.h | 2 -- sound/core/info.c | 13 ------------- 2 files changed, 15 deletions(-)
include/sound/info.h +0 -2
@@ -50,8 +50,6 @@ struct snd_info_entry_ops {__poll_t (*poll)(struct snd_info_entry *entry,void *file_private_data,struct file *file,poll_table *wait); -int (*ioctl)(struct snd_info_entry *entry,void *file_private_data, -struct file *file,unsigned int cmd,unsigned long arg);int (*mmap)(struct snd_info_entry *entry,void *file_private_data,struct inode *inode,struct file *file,struct vm_area_struct *vma);
sound/core/info.c +0 -13
@@ -201,18 +201,6 @@ static __poll_t snd_info_entry_poll(struct file *file, poll_table *wait)return mask; } -static long snd_info_entry_ioctl (struct file *file,unsigned int cmd, -unsigned long arg) -{ -struct snd_info_private_data *data = file->private_data; -struct snd_info_entry *entry = data->entry; - -if (!entry->c.ops->ioctl) -return -ENOTTY ; -return entry->c.ops->ioctl (entry, data->file_private_data, - file, cmd, arg); -} -static int snd_info_entry_mmap (struct file *file,struct vm_area_struct *vma) {struct inode *inode =file_inode (file);
@@ -283,7 +271,6 @@ static const struct proc_ops snd_info_entry_operations = .proc_write_buf = snd_info_entry_write, .proc_write_size = PAGE_SIZE, .proc_poll = snd_info_entry_poll, - .proc_ioctl = snd_info_entry_ioctl, .proc_mmap = snd_info_entry_mmap, .proc_open = snd_info_entry_open, .proc_release = snd_info_entry_release,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 25/26] ALSA: info: drop the ioctl hook of data entries
Sashiko has reviewed this patch and found no issues.
Quoted 3 lines
No driver implements ->ioctl() of struct
snd_info_entry_ops.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
Christian Brauner
maintainerPATCH RESEND v2 26/26 ALSA: info: drop the poll_table from the info entry poll op
In reply to Christian Braunerprocfs owns the wait queue a /proc/asound file is polled on and wakes the pollers through proc_poll_notify(), so the poll op of an info entry has nothing to do with the poll_table anymore and only reports the mask. Nothing in the tree implements the op.
--- include/sound/info.h | 3 +-- sound/core/info.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
include/sound/info.h +1 -2
@@ -48,8 +48,7 @@ struct snd_info_entry_ops { void *file_private_data, struct file *file, loff_t offset, int orig);__poll_t (*poll)(struct snd_info_entry *entry, -void *file_private_data,struct file *file, -poll_table *wait); +void *file_private_data,struct file *file);int (*mmap)(struct snd_info_entry *entry,void *file_private_data,struct inode *inode,struct file *file,struct vm_area_struct *vma);
sound/core/info.c +1 -1
@@ -193,7 +193,7 @@ static __poll_t snd_info_entry_poll(struct file *file, poll_table *wait)if (entry->c.ops->poll)return entry->c.ops->poll (entry, data->file_private_data, - file, wait); + file);if (entry->c.ops->read) mask |=EPOLLIN |EPOLLRDNORM ;if (entry->c.ops->write)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 26/26] ALSA: info: drop the poll_table from the info entry poll op
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
procfs owns the wait queue a
/proc/asoundfile is polled on and wakes the pollers throughproc_poll_notify(), so the poll op of an info entry has nothing to do with thepoll_tableanymore and only reports the mask. Nothing in the tree implements the op.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
Christian Brauner
maintainerv2 cover proc: convert the fs, kernel and mm entries (Part 5/7)
In reply to Christian BraunerPart 5/7 of "proc: move procfs to what kernfs does", on top of part 2 and independent of parts 3, 4 and 6:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
This converts the proc entries of jbd2, jfs, lockd, nfsd, ntfs3 and cifs, the irq affinity files, latencytop, lockdep, /proc/profile, /proc/pressure, kallsyms, /proc/modules, dynamic_debug, sysvipc, allocinfo, /proc/swaps and /proc/config.gz to what "proc: let procfs own the data path" set up. Afterwards the entries' code only runs with the entry pinned and never touches userspace memory. One patch per subsystem and method.
- procfs owns the seq_file of jbd2's info file, /proc/fs/nfs/exports, the smbdirect files, /proc/lock_stat, the pressure files, /proc/kallsyms, /proc/modules, the sysvipc files, /proc/allocinfo and /proc/swaps. Their open and release hooks only do what is left, a snapshot, an iterator or a reference, and reading one of them no longer holds up its removal.
- procfs copies in the writes of jfs's loglevel, nlm_end_grace, ntfs3's label, the cifs files, the irq affinity masks, /proc/latency_stats, /proc/lock_stat, /proc/profile, the pressure triggers and dynamic_debug's control. Most of them just parse procfs' copy, the affinity masks and dynamic_debug ask for a larger write size. Where a write larger than anything the entry parses now fails with -EINVAL from procfs the commit says so.
- procfs copies out the reads of nlm_end_grace, /proc/profile and /proc/config.gz. readprofile reads all of /proc/profile in one go and so does whoever reads /proc/config.gz, both ask for PROC_ENTRY_FULL_READS so that reading all of them at once keeps working.
- procfs copies the ioctl arguments of /proc/allocinfo in and out and converts the pointers of 32-bit tasks, so the compat ioctl goes away.
- /proc/profile and /proc/pressure/* are never removed and are marked permanent, procfs calls into them without pinning.
- /proc/swaps and the pressure files move their pollers to the wait queue procfs owns for the entry. A pressure file has one queue for all its triggers then, like the cgroup pressure files have in kernfs, so every poller of the file is woken when any trigger on it fires and each reports the state of its own trigger. That's a few extra wakeups for the daemons that poll these files, I don't think it matters.
The selftest unloads configs.ko while a reader of /proc/config.gz faults in procfs' copy to userspace. On a KASAN and lockdep kernel it fails without the series and passes with it. Build tested per commit on x86_64 and with W=1 on the touched objects. The proc and allocinfo selftests behave the same with and without the series and so do the entries I could get at in a VM.
---
Changes in v2:
- psi and swapfile let procfs own the wait queues of the pressure files
and /proc/swaps, a pressure file has one queue for all its triggers
- /proc/profile reads go through procfs now like everything else, with PROC_ENTRY_FULL_READS; v1 left it reading straight into userspace
- Acked-by from Chuck on lockd and nfsd
- the selftest commit applies on the core series alone
- rebased onto v7.4-rc1
- Link to v1: https://patch.msgid.link/[email protected]
---
Christian Brauner (30):
jbd2: let procfs own the seq_file of the info file
jfs: let procfs copy in writes to the loglevel file
lockd: let procfs copy in writes to nlm_end_grace
lockd: let procfs copy out reads of nlm_end_grace
nfsd: factor out setting up the exports seq_file
nfsd: let procfs own the seq_file of /proc/fs/nfs/exports
ntfs3: let procfs copy in writes to the label file
smb: client: let procfs own the seq_file of the smbdirect files
smb: client: let procfs copy in writes
genirq/proc: let procfs copy in the affinity masks
latencytop: let procfs copy in writes to /proc/latency_stats locking/lockdep: let procfs own the seq_file of /proc/lock_stat locking/lockdep: let procfs copy in writes to /proc/lock_stat
profiling: let procfs copy in writes to /proc/profile
profiling: let procfs copy out reads of /proc/profile
profiling: mark /proc/profile permanent
sched/psi: let procfs own the seq_file of the pressure files sched/psi: let procfs copy in trigger writes
sched/psi: mark the pressure files permanent
sched/psi: let procfs own the wait queue of the pressure files
kallsyms: let procfs own the seq_file of /proc/kallsyms
module: procfs: let procfs own the seq_file of /proc/modules
dyndbg: let procfs copy in writes to /proc/dynamic_debug/control
ipc: let procfs own the seq_file of the sysvipc files
alloc_tag: let procfs own the seq_file of /proc/allocinfo
alloc_tag: let procfs copy the ioctl arguments of /proc/allocinfo mm/swapfile: let procfs own the seq_file of /proc/swaps mm/swapfile: let procfs own the wait queue of /proc/swaps kernel/configs: let procfs copy out reads of /proc/config.gz selftests/proc: check that unloading configs doesn't wait for a reader
fs/jbd2/journal.c | 33 ++--- fs/jfs/jfs_debug.c | 11 +- fs/lockd/procfs.c | 19 +-- fs/nfsd/nfsctl.c | 41 ++++-- fs/ntfs3/super.c | 27 ++-- fs/smb/client/cifs_debug.c | 71 ++++------ fs/smb/client/dfs_cache.c | 13 +- include/linux/psi.h | 3 +- include/linux/psi_types.h | 8 +- ipc/util.c | 14 +- kernel/cgroup/cgroup.c | 2 +- kernel/configs.c | 7 +- kernel/irq/proc.c | 27 ++-- kernel/kallsyms.c | 12 +- kernel/latencytop.c | 5 +- kernel/locking/lockdep_proc.c | 60 ++++---- kernel/module/procfs.c | 19 +-- kernel/profile.c | 22 ++- kernel/sched/psi.c | 112 ++++++--------- lib/dynamic_debug.c | 34 +++-- mm/alloc_tag.c | 75 ++++------ mm/swapfile.c | 23 +-- tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/config | 2 + .../proc/proc-remove-slow-config-reader.c | 157 +++++++++++++++++++++ 26 files changed, 430 insertions(+), 369 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261101-work-procfs-fs-41f9fdc489cb
prerequisite-change-id: 20261101-work-procfs-core-8fa4a4f412cf:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
Christian Brauner
maintainerPATCH RESEND v2 1/30 jbd2: let procfs own the seq_file of the info file
Declare the seq_operations and the size of the session state and let procfs open and free the seq_file of /proc/fs/jbd2/<dev>/info. ->proc_open() only takes the snapshot of the statistics now and ->proc_release() frees it. Reading the file then no longer holds up its removal when the journal goes away.
--- fs/jbd2/journal.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-)
fs/jbd2/journal.c +9 -24
@@ -1173,51 +1173,36 @@ static const struct seq_operations jbd2_seq_info_ops = { .show = jbd2_seq_info_show, }; +/* procfs opened the seq_file and allocated @s */ static int jbd2_seq_info_open (struct inode *inode,struct file *file) {journal_t *journal =pde_data (inode); -struct jbd2_stats_proc_session *s; -int rc, size; +struct jbd2_stats_proc_session *s = ((struct seq_file *)file->private_data)->private; +int size =sizeof (struct transaction_stats_s ); - s =kmalloc_obj (*s); -if (s ==NULL ) -return -ENOMEM ; - size =sizeof (struct transaction_stats_s ); s->stats =kmalloc (size,GFP_KERNEL ); -if (s->stats ==NULL ) { -kfree (s); +if (s->stats ==NULL )return -ENOMEM ; - }spin_lock (&journal->j_history_lock);memcpy (s->stats, &journal->j_stats, size); s->journal = journal;spin_unlock (&journal->j_history_lock); - - rc =seq_open (file, &jbd2_seq_info_ops); -if (rc ==0 ) { -struct seq_file *m = file->private_data; - m->private = s; - }else { -kfree (s->stats); -kfree (s); - } -return rc; - +return 0 ; }static int jbd2_seq_info_release (struct inode *inode,struct file *file) {struct seq_file *seq = file->private_data;struct jbd2_stats_proc_session *s = seq->private; +kfree (s->stats); -kfree (s); -return seq_release (inode, file); +return 0 ; }static const struct proc_ops jbd2_info_proc_ops = { + .proc_seq_ops = &jbd2_seq_info_ops, + .proc_state_size =sizeof (struct jbd2_stats_proc_session ), .proc_open = jbd2_seq_info_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_release = jbd2_seq_info_release, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 01/30] jbd2: let procfs own the seq_file of the info file
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Declare the
seq_operationsand the size of the session state and let procfs open and free theseq_fileof /proc/fs/jbd2/<dev>/info. ->proc_open() only takes the snapshot of the statistics now and ->proc_release() frees it. Reading the file then no longer holds up its removal when the journal goes away.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Christian Brauner
maintainerPATCH RESEND v2 2/30 jfs: let procfs copy in writes to the loglevel file
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and take the level from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now and so do empty writes, which looked at a byte that wasn't written before.
--- fs/jfs/jfs_debug.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
fs/jfs/jfs_debug.c +4 -7
@@ -23,13 +23,10 @@ static int jfs_loglevel_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t jfs_loglevel_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *ppos) +static ssize_t jfs_loglevel_proc_write (struct file *file,char *buffer, +size_t count,loff_t *ppos) { -char c; - -if (get_user (c, buffer)) -return -EFAULT ; +char c = buffer[0 ];/* yes, I know this is an ASCIIism. --hch */ if (c <'0' || c >'9' )
@@ -40,7 +37,7 @@ static ssize_t jfs_loglevel_proc_write(struct file *file,static const struct proc_ops jfs_loglevel_proc_ops = { .proc_show = jfs_loglevel_proc_show, - .proc_write = jfs_loglevel_proc_write, + .proc_write_buf = jfs_loglevel_proc_write, };#endif
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 02/30] jfs: let procfs copy in writes to the loglevel file
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and take the level from that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow and so do empty writes, which looked at a byte that wasn't written before.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Christian Brauner
maintainerPATCH RESEND v2 3/30 lockd: let procfs copy in writes to nlm_end_grace
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry. simple_transaction_get() was only used to get a copy of what was written, so look at procfs' copy instead and drop the transaction. A second write to the same file doesn't fail with -EBUSY anymore. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL from procfs instead of -EFBIG from simple_transaction_get(), which refused a few bytes less.
--- fs/lockd/procfs.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
fs/lockd/procfs.c +3 -10
@@ -18,21 +18,15 @@* We only allow strings that start with 'Y', 'y', or '1'. */ static ssize_t -nlm_end_grace_write (struct file *file,const char __user *buf,size_t size, -loff_t *pos) +nlm_end_grace_write (struct file *file,char *buf,size_t size,loff_t *pos) { -char *data;struct lockd_net *ln =net_generic (current->nsproxy->net_ns, lockd_net_id);if (size <1 )return -EINVAL ; - data =simple_transaction_get (file, buf, size); -if (IS_ERR (data)) -return PTR_ERR (data); - -switch (data[0 ]) { +switch (buf[0 ]) {case 'Y' :case 'y' :case '1' :
@@ -61,10 +55,9 @@ nlm_end_grace_read(struct file *file, char __user *buf, size_t size, }static const struct proc_ops lockd_end_grace_proc_ops = { - .proc_write = nlm_end_grace_write, + .proc_write_buf = nlm_end_grace_write, .proc_read = nlm_end_grace_read, .proc_lseek = default_llseek, - .proc_release = simple_transaction_release, };int __init
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 03/30] lockd: let procfs copy in writes to nlm_end_grace
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry.
simple_transaction_get()was only used to get a copy of what was written, so look at procfs' copy instead and drop the transaction. A second write to the same file doesn't fail with-EBUSYanymore. Writes larger thanPAGE_SIZE- 1 bytes fail with-EINVALfrom procfs instead of-EFBIGfromsimple_transaction_get(), which refused a few bytes less.Acked-by Chuck Lever <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Christian Brauner
maintainerPATCH RESEND v2 4/30 lockd: let procfs copy out reads of nlm_end_grace
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry.
--- fs/lockd/procfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/lockd/procfs.c +3 -3
@@ -40,7 +40,7 @@ nlm_end_grace_write(struct file *file, char *buf, size_t size, loff_t *pos) }static ssize_t -nlm_end_grace_read (struct file *file,char __user *buf,size_t size, +nlm_end_grace_read (struct file *file,char *buf,size_t size,loff_t *pos) { struct lockd_net *ln = net_generic(current->nsproxy->net_ns,
@@ -51,12 +51,12 @@ nlm_end_grace_read(struct file *file, char __user *buf, size_t size, resp[1 ] ='\n' ; resp[2 ] ='\0' ; -return simple_read_from_buffer (buf, size, pos, resp,sizeof (resp) -1 ); +return memory_read_from_buffer (buf, size, pos, resp,sizeof (resp) -1 ); }static const struct proc_ops lockd_end_grace_proc_ops = { .proc_write_buf = nlm_end_grace_write, - .proc_read = nlm_end_grace_read, + .proc_read_buf = nlm_end_grace_read, .proc_lseek = default_llseek, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 04/30] lockd: let procfs copy out reads of nlm_end_grace
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Implement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry.
Acked-by Chuck Lever <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Christian Brauner
maintainerPATCH RESEND v2 5/30 nfsd: factor out setting up the exports seq_file
In reply to Christian BraunerMove setting up ->private and taking the reference to the network namespace into exports_net_init() and dropping it into exports_net_put(). The procfs file needs them without the seq_open() and seq_release() around them.
No functional changes.
--- fs/nfsd/nfsctl.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
fs/nfsd/nfsctl.c +17 -9
@@ -143,28 +143,36 @@ static const struct file_operations transaction_ops = { .llseek = default_llseek, }; +static void exports_net_init (struct net *net,struct seq_file *seq) +{ +struct nfsd_net *nn =net_generic (net, nfsd_net_id); + + seq->private = nn->svc_export_cache; +get_net (net); +} + +static void exports_net_put (struct seq_file *seq) +{ +struct cache_detail *cd = seq->private; + +put_net (cd->net); +} +static int exports_net_open (struct net *net,struct file *file) {int err; -struct seq_file *seq; -struct nfsd_net *nn =net_generic (net, nfsd_net_id); err =seq_open (file, &nfs_exports_op);if (err)return err; - seq = file->private_data; - seq->private = nn->svc_export_cache; -get_net (net); +exports_net_init (net, file->private_data);return 0 ; }static int exports_release (struct inode *inode,struct file *file) { -struct seq_file *seq = file->private_data; -struct cache_detail *cd = seq->private; - -put_net (cd->net); +exports_net_put (file->private_data);return seq_release (inode, file); }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 05/30] nfsd: factor out setting up the exports seq_file
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Move setting up ->private and taking the reference to the network namespace into
exports_net_init()and dropping it intoexports_net_put(). The procfs file needs them without theseq_open()andseq_release()around them.No functional changes.
Acked-by Chuck Lever <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Christian Brauner
maintainerPATCH RESEND v2 6/30 nfsd: let procfs own the seq_file of /proc/fs/nfs/exports
In reply to Christian BraunerDeclare the seq_operations and let procfs open and free the seq_file. ->proc_open() and ->proc_release() only set up ->private and take and drop the reference to the network namespace now. Reading the file then no longer holds up its removal.
--- fs/nfsd/nfsctl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
fs/nfsd/nfsctl.c +11 -4
@@ -1407,16 +1407,23 @@ MODULE_ALIAS_FS("nfsd");#ifdef CONFIG_PROC_FS +/* procfs opens the seq_file */ static int exports_proc_open (struct inode *inode,struct file *file) { -return exports_net_open (current->nsproxy->net_ns, file); +exports_net_init (current->nsproxy->net_ns, file->private_data); +return 0 ; +} + +static int exports_proc_release (struct inode *inode,struct file *file) +{ +exports_net_put (file->private_data); +return 0 ; }static const struct proc_ops exports_proc_ops = { + .proc_seq_ops = &nfs_exports_op, .proc_open = exports_proc_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = exports_release, + .proc_release = exports_proc_release, };static int create_proc_exports_entry (void )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 06/30] nfsd: let procfs own the seq_file of /proc/fs/nfs/exports
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Declare the
seq_operationsand let procfs open and free theseq_file. ->proc_open() and ->proc_release() only set up ->private and take and drop the reference to the network namespace now. Reading the file then no longer holds up its removal.Acked-by Chuck Lever <[email protected]>Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Christian Brauner
maintainerPATCH RESEND v2 7/30 ntfs3: let procfs copy in writes to the label file
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and set the label from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL from procfs now. A write that large only ever worked when most of it was trailing newlines or came after a NUL, ntfs_set_label() refused a label that long with -ENAMETOOLONG or -EFBIG.
--- fs/ntfs3/super.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-)
fs/ntfs3/super.c +9 -18
@@ -560,37 +560,28 @@ static int ntfs3_label_show(struct seq_file *m, void *o) }/* write /proc/fs/ntfs3/<dev>/label */ -static ssize_t ntfs3_label_write (struct file *file,const char __user *buffer, -size_t count,loff_t *ppos) +static ssize_t ntfs3_label_write (struct file *file,char *buf,size_t count, +loff_t *ppos) {int err;struct super_block *sb =pde_data (file_inode (file)); -ssize_t ret = count; -u8 *label; +size_t len = count;if (sb_rdonly (sb))return -EROFS ; - label =memdup_user (buffer, count); -if (IS_ERR (label)) -return PTR_ERR (label); +while (len >0 && buf[len -1 ] =='\n' ) + len -=1 ; -while (ret >0 && label[ret -1 ] =='\n' ) - ret -=1 ; - - err =ntfs_set_label (sb->s_fs_info, label, ret); + err =ntfs_set_label (sb->s_fs_info, (u8 *)buf, len);if (err <0 ) {ntfs_err (sb,"failed (%d) to write label" , err); - ret = err; - goto out; +return err; } *ppos += count; - ret = count; -out: -kfree (label); -return ret; +return count; }static const struct proc_ops ntfs3_volinfo_fops = {
@@ -599,7 +590,7 @@ static const struct proc_ops ntfs3_volinfo_fops = {static const struct proc_ops ntfs3_label_fops = { .proc_show = ntfs3_label_show, - .proc_write = ntfs3_label_write, + .proc_write_buf = ntfs3_label_write, };static void ntfs_create_procdir (struct super_block *sb)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 07/30] ntfs3: let procfs copy in writes to the label file
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and set the label from that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALfrom procfs now. A write that large only ever worked when most of it was trailing newlines or came after a NUL,ntfs_set_label()refused a label that long with-ENAMETOOLONGor-EFBIG.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Christian Brauner
maintainerPATCH RESEND v2 8/30 smb: client: let procfs own the seq_file of the smbdirect files
In reply to Christian BraunerDeclare the show function in PROC_FILE_DEFINE() and let procfs open and free the seq_file. That makes the open functions unnecessary.
--- fs/smb/client/cifs_debug.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
fs/smb/client/cifs_debug.c +1 -8
@@ -873,16 +873,9 @@ static int name##_proc_show(struct seq_file *m, void *v) \seq_printf (m,"%d\n" , name); \return 0 ; \ } \ -static int name##_open(struct inode *inode, struct file *file) \ -{ \ - return single_open(file, name##_proc_show, NULL); \ -} \ \ static const struct proc_ops cifs_##name##_proc_fops = { \ - .proc_open = name##_open, \ - .proc_read = seq_read, \ - .proc_lseek = seq_lseek, \ - .proc_release = single_release, \ + .proc_show = name##_proc_show, \ .proc_write = name##_write, \ }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 08/30] smb: client: let procfs own the seq_file of the smbdirect files
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Declare the show function in
PROC_FILE_DEFINE()and let procfs open and free theseq_file. That makes the open functions unnecessary.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Christian Brauner
maintainerPATCH RESEND v2 9/30 smb: client: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for the files in /proc/fs/cifs so procfs copies in what is written before it pins the entry, and parse what was written from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now, SecurityFlags never took more than 11 bytes. Empty writes to cifsFYI and dfscache fail with -EINVAL too, they looked at a byte that wasn't written before. kstrtoint_from_user() looked at the first 34 bytes of a write to cifs_debug_dirs and the smbdirect files, now the whole write is parsed.
--- fs/smb/client/cifs_debug.c | 62 +++++++++++++++++++--------------------------- fs/smb/client/dfs_cache.c | 13 +++------- 2 files changed, 29 insertions(+), 46 deletions(-)
fs/smb/client/cifs_debug.c +26 -36
@@ -359,12 +359,12 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)#ifdef CONFIG_CIFS_DEBUG /* Drop all cached directory entries across all CIFS mounts. */ -static ssize_t cifs_debug_dirs_proc_write (struct file *file,const char __user *buffer, +static ssize_t cifs_debug_dirs_proc_write (struct file *file,char *buffer,size_t count,loff_t *ppos) {int rc, v; - rc =kstrtoint_from_user (buffer, count,10 , &v); + rc =kstrtoint (buffer,10 , &v);if (rc)return rc;
@@ -390,7 +390,7 @@ static ssize_t cifs_debug_dirs_proc_write(struct file *file, const char __user *static const struct proc_ops cifs_debug_dirs_proc_ops = { .proc_show = cifs_debug_dirs_proc_show, - .proc_write = cifs_debug_dirs_proc_write, + .proc_write_buf = cifs_debug_dirs_proc_write, };#endif /* CONFIG_CIFS_DEBUG */
@@ -713,8 +713,8 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t cifs_stats_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *ppos) +static ssize_t cifs_stats_proc_write (struct file *file,char *buffer, +size_t count,loff_t *ppos) {bool bv;int rc;
@@ -722,7 +722,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,struct cifs_ses *ses;struct cifs_tcon *tcon; - rc =kstrtobool_from_user (buffer, count, &bv); + rc =kstrtobool (buffer, &bv);if (rc ==0 ) {#ifdef CONFIG_CIFS_STATS2 int i;
@@ -854,16 +854,16 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)static const struct proc_ops cifs_stats_proc_ops = { .proc_show = cifs_stats_proc_show, - .proc_write = cifs_stats_proc_write, + .proc_write_buf = cifs_stats_proc_write, };#ifdef CONFIG_CIFS_SMB_DIRECT #define PROC_FILE_DEFINE (name) \ -static ssize_t name##_write(struct file *file, const char __user *buffer, \ +static ssize_t name##_write(struct file *file, char *buffer, \ size_t count, loff_t *ppos) \ { \ int rc; \ - rc = kstrtoint_from_user(buffer, count, 10, &name); \ + rc = kstrtoint(buffer, 10, &name); \ if (rc) \ return rc; \ return count; \
@@ -876,7 +876,7 @@ static int name##_proc_show(struct seq_file *m, void *v) \ \ static const struct proc_ops cifs_##name##_proc_fops = { \ .proc_show = name##_proc_show, \ - .proc_write = name##_write, \ + .proc_write_buf = name##_write, \ }PROC_FILE_DEFINE (rdma_readwrite_threshold);
@@ -990,16 +990,12 @@ static int cifsFYI_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t cifsFYI_proc_write (struct file *file,const char __user *buffer, +static ssize_t cifsFYI_proc_write (struct file *file,char *buffer,size_t count,loff_t *ppos) { -char c[2 ] = {'\0' }; +char c[2 ] = { buffer[0 ] };bool bv; -int rc; - rc =get_user (c[0 ], buffer); -if (rc) -return rc;if (kstrtobool (c, &bv) ==0 ) cifsFYI = bv;else if ((c[0 ] >'1' ) && (c[0 ] <='9' ))
@@ -1012,7 +1008,7 @@ static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,static const struct proc_ops cifsFYI_proc_ops = { .proc_show = cifsFYI_proc_show, - .proc_write = cifsFYI_proc_write, + .proc_write_buf = cifsFYI_proc_write, };static int cifs_linux_ext_proc_show (struct seq_file *m,void *v)
@@ -1021,12 +1017,12 @@ static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t cifs_linux_ext_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *ppos) +static ssize_t cifs_linux_ext_proc_write (struct file *file,char *buffer, +size_t count,loff_t *ppos) {int rc; - rc =kstrtobool_from_user (buffer, count, &linuxExtEnabled); + rc =kstrtobool (buffer, &linuxExtEnabled);if (rc)return rc;
@@ -1035,7 +1031,7 @@ static ssize_t cifs_linux_ext_proc_write(struct file *file,static const struct proc_ops cifs_linux_ext_proc_ops = { .proc_show = cifs_linux_ext_proc_show, - .proc_write = cifs_linux_ext_proc_write, + .proc_write_buf = cifs_linux_ext_proc_write, };static int cifs_lookup_cache_proc_show (struct seq_file *m,void *v)
@@ -1044,12 +1040,12 @@ static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t cifs_lookup_cache_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *ppos) +static ssize_t cifs_lookup_cache_proc_write (struct file *file,char *buffer, +size_t count,loff_t *ppos) {int rc; - rc =kstrtobool_from_user (buffer, count, &lookupCacheEnabled); + rc =kstrtobool (buffer, &lookupCacheEnabled);if (rc)return rc;
@@ -1058,7 +1054,7 @@ static ssize_t cifs_lookup_cache_proc_write(struct file *file,static const struct proc_ops cifs_lookup_cache_proc_ops = { .proc_show = cifs_lookup_cache_proc_show, - .proc_write = cifs_lookup_cache_proc_write, + .proc_write_buf = cifs_lookup_cache_proc_write, };static int traceSMB_proc_show (struct seq_file *m,void *v)
@@ -1067,12 +1063,12 @@ static int traceSMB_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t traceSMB_proc_write (struct file *file,const char __user *buffer, +static ssize_t traceSMB_proc_write (struct file *file,char *buffer,size_t count,loff_t *ppos) {int rc; - rc =kstrtobool_from_user (buffer, count, &traceSMB); + rc =kstrtobool (buffer, &traceSMB);if (rc)return rc;
@@ -1081,7 +1077,7 @@ static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,static const struct proc_ops traceSMB_proc_ops = { .proc_show = traceSMB_proc_show, - .proc_write = traceSMB_proc_write, + .proc_write_buf = traceSMB_proc_write, };static int cifs_security_flags_proc_show (struct seq_file *m,void *v)
@@ -1111,21 +1107,15 @@ cifs_security_flags_handle_must_flags(unsigned int *flags) }static ssize_t cifs_security_flags_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *ppos) +char *flags_string,size_t count,loff_t *ppos) {int rc;unsigned int flags; -char flags_string[12 ];bool bv;if ((count <1 ) || (count >11 ))return -EINVAL ; -memset (flags_string,0 ,sizeof (flags_string)); - -if (copy_from_user (flags_string, buffer, count)) -return -EFAULT ; -if (count <3 ) {/* single char or single char followed by null */ if (kstrtobool (flags_string, &bv) ==0 ) {
@@ -1176,7 +1166,7 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,static const struct proc_ops cifs_security_flags_proc_ops = { .proc_show = cifs_security_flags_proc_show, - .proc_write = cifs_security_flags_proc_write, + .proc_write_buf = cifs_security_flags_proc_write, };/* To make it easier to debug, can help to show mount params */
fs/smb/client/dfs_cache.c +3 -10
@@ -191,17 +191,10 @@ static int dfscache_proc_show(struct seq_file *m, void *v)return 0 ; } -static ssize_t dfscache_proc_write (struct file *file,const char __user *buffer, +static ssize_t dfscache_proc_write (struct file *file,char *buffer,size_t count,loff_t *ppos) { -char c; -int rc; - - rc =get_user (c, buffer); -if (rc) -return rc; - -if (c !='0' ) +if (buffer[0 ] !='0' )return -EINVAL ;cifs_dbg (FYI ,"clearing dfs cache\n" );
@@ -215,7 +208,7 @@ static ssize_t dfscache_proc_write(struct file *file, const char __user *buffer,const struct proc_ops dfscache_proc_ops = { .proc_show = dfscache_proc_show, - .proc_write = dfscache_proc_write, + .proc_write_buf = dfscache_proc_write, };#ifdef CONFIG_CIFS_DEBUG2
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 09/30] smb: client: let procfs copy in writes
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
Implement ->proc_write_buf() for the files in
/proc/fs/cifsso procfs copies in what is written before it pins the entry, and parse what was written from that copy. Writes larger thanPAGE_SIZE- 1 bytes fail with-EINVALnow, SecurityFlags never took more than 11 bytes. Empty writes to cifsFYI and dfscache fail with-EINVALtoo, they looked at a byte that wasn't written before.kstrtoint_from_user()looked at the first 34 bytes of a write tocifs_debug_dirsand the smbdirect files, now the whole write is parsed.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Christian Brauner
maintainerPATCH RESEND v2 10/30 genirq/proc: let procfs copy in the affinity masks
In reply to Christian BraunerImplement ->proc_write_buf() for smp_affinity, smp_affinity_list and default_smp_affinity so procfs copies in what is written before it pins the entry, and parse the masks from that copy. A list of CPUs can be longer than a page on large machines, so the files take as much as memdup_user_nul() could copy in before. Anything larger fails with -EINVAL instead of -ENOMEM.
--- kernel/irq/proc.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
kernel/irq/proc.c +17 -10
@@ -9,6 +9,7 @@#include <linux/gfp.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> +#include <linux/slab.h> #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/kernel_stat.h>
@@ -134,8 +135,11 @@ static inline int irq_select_affinity_usr(unsigned int irq) }#endif +/* lists of CPUs can outgrow a page, take what memdup_user_nul() took */ +#define IRQ_AFFINITY_WRITE_SIZE (KMALLOC_MAX_SIZE - 1) +static ssize_t write_irq_affinity (int type,struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {unsigned int irq = (int )(long )pde_data (file_inode (file));cpumask_var_t new_value;
@@ -148,9 +152,9 @@ static ssize_t write_irq_affinity(int type, struct file *file,return -ENOMEM ;if (type) - err =cpumask_parselist_user (buffer, count, new_value); + err =cpulist_parse (buffer, new_value);else - err =cpumask_parse_user (buffer, count, new_value); + err =cpumask_parse (buffer, new_value);if (err) goto free_cpumask;
@@ -177,25 +181,27 @@ free_cpumask: }static ssize_t irq_affinity_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {return write_irq_affinity (0 , file, buffer, count, pos); }static ssize_t irq_affinity_list_proc_write (struct file *file, -const char __user *buffer,size_t count,loff_t *pos) +char *buffer,size_t count,loff_t *pos) {return write_irq_affinity (1 , file, buffer, count, pos); }static const struct proc_ops irq_affinity_proc_ops = { .proc_show = irq_affinity_proc_show, - .proc_write = irq_affinity_proc_write, + .proc_write_buf = irq_affinity_proc_write, + .proc_write_size =IRQ_AFFINITY_WRITE_SIZE , };static const struct proc_ops irq_affinity_list_proc_ops = { .proc_show = irq_affinity_list_proc_show, - .proc_write = irq_affinity_list_proc_write, + .proc_write_buf = irq_affinity_list_proc_write, + .proc_write_size =IRQ_AFFINITY_WRITE_SIZE , };#ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
@@ -217,7 +223,7 @@ static int default_affinity_show(struct seq_file *m, void *v) }static ssize_t default_affinity_write (struct file *file, -const char __user *buffer,size_t count,loff_t *ppos) +char *buffer,size_t count,loff_t *ppos) {cpumask_var_t new_value;int err;
@@ -225,7 +231,7 @@ static ssize_t default_affinity_write(struct file *file,if (!zalloc_cpumask_var (&new_value,GFP_KERNEL ))return -ENOMEM ; - err =cpumask_parse_user (buffer, count, new_value); + err =cpumask_parse (buffer, new_value);if (err) goto out;
@@ -249,7 +255,8 @@ out:static const struct proc_ops default_affinity_proc_ops = { .proc_show = default_affinity_show, - .proc_write = default_affinity_write, + .proc_write_buf = default_affinity_write, + .proc_write_size =IRQ_AFFINITY_WRITE_SIZE , };static int irq_node_proc_show (struct seq_file *m,void *v)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 10/30] genirq/proc: let procfs copy in the affinity masks
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Implement ->proc_write_buf() for
smp_affinity,smp_affinity_listanddefault_smp_affinityso procfs copies in what is written before it pins the entry, and parse the masks from that copy. A list of CPUs can be longer than a page on large machines, so the files take as much asmemdup_user_nul()could copy in before. Anything larger fails with-EINVALinstead of-ENOMEM.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Christian Brauner
maintainerPATCH RESEND v2 11/30 latencytop: let procfs copy in writes to /proc/latency_stats
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry. The write only clears the statistics and doesn't look at what was written anyway. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- kernel/latencytop.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/latencytop.c +2 -3
@@ -267,8 +267,7 @@ static int lstats_show(struct seq_file *m, void *v) }static ssize_t -lstats_write (struct file *file,const char __user *buf,size_t count, -loff_t *offs) +lstats_write (struct file *file,char *buf,size_t count,loff_t *offs) {clear_global_latency_tracing ();
@@ -277,7 +276,7 @@ lstats_write(struct file *file, const char __user *buf, size_t count,static const struct proc_ops lstats_proc_ops = { .proc_show = lstats_show, - .proc_write = lstats_write, + .proc_write_buf = lstats_write, };static int __init init_lstats_procfs (void )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 11/30] latencytop: let procfs copy in writes to /proc/latency_stats
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry. The write only clears the statistics and doesn't look at what was written anyway. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Christian Brauner
maintainerPATCH RESEND v2 12/30 locking/lockdep: let procfs own the seq_file of /proc/lock_stat
In reply to Christian BraunerDeclare the seq_operations and let procfs open and free the seq_file. ->proc_open() only takes the snapshot of the statistics now and ->proc_release() frees it.
--- kernel/locking/lockdep_proc.c | 48 +++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 27 deletions(-)
kernel/locking/lockdep_proc.c +21 -27
@@ -638,40 +638,35 @@ static const struct seq_operations lockstat_ops = { .show = ls_show, }; +/* procfs opens the seq_file */ static int lock_stat_open (struct inode *inode,struct file *file) { -int res; -struct lock_class *class;struct lock_stat_seq *data =vmalloc (sizeof (struct lock_stat_seq )); +struct lock_stat_data *iter; +struct seq_file *m = file->private_data; +struct lock_class *class; +unsigned long idx;if (!data)return -ENOMEM ; - res =seq_open (file, &lockstat_ops); -if (!res) { -struct lock_stat_data *iter = data->stats; -struct seq_file *m = file->private_data; -unsigned long idx; - - iterate_lock_classes(idx, class) { -if (!test_bit (idx, lock_classes_in_use)) -continue ; - iter->class = class; -lock_stats (class, &iter->stats); - iter++; - } - - data->iter_end = iter; + iter = data->stats; + iterate_lock_classes(idx, class) { +if (!test_bit (idx, lock_classes_in_use)) +continue ; + iter->class = class; +lock_stats (class, &iter->stats); + iter++; + } -sort (data->stats, data->iter_end - data->stats, -sizeof (struct lock_stat_data ), - lock_stat_cmp,NULL ); + data->iter_end = iter; - m->private = data; - }else -vfree (data); +sort (data->stats, data->iter_end - data->stats, +sizeof (struct lock_stat_data ), + lock_stat_cmp,NULL ); -return res; + m->private = data; +return 0 ; } static ssize_t lock_stat_write(struct file *file, const char __user *buf,
@@ -702,14 +697,13 @@ static int lock_stat_release(struct inode *inode, struct file *file)struct seq_file *seq = file->private_data;vfree (seq->private); - return seq_release(inode, file); + return 0; }static const struct proc_ops lock_stat_proc_ops = { + .proc_seq_ops = &lockstat_ops, .proc_open = lock_stat_open, .proc_write = lock_stat_write, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_release = lock_stat_release, };#endif /* CONFIG_LOCK_STAT */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 12/30] locking/lockdep: let procfs own the seq_file of /proc/lock_stat
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Declare the
seq_operationsand let procfs open and free theseq_file. ->proc_open() only takes the snapshot of the statistics now and ->proc_release() frees it.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Christian Brauner
maintainerPATCH RESEND v2 13/30 locking/lockdep: let procfs copy in writes to /proc/lock_stat
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and look at the first character of that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- kernel/locking/lockdep_proc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
kernel/locking/lockdep_proc.c +4 -8
@@ -669,18 +669,14 @@ static int lock_stat_open(struct inode *inode, struct file *file)return 0 ; } -static ssize_t lock_stat_write (struct file *file,const char __user *buf, -size_t count,loff_t *ppos) +static ssize_t lock_stat_write (struct file *file,char *buf,size_t count, +loff_t *ppos) {struct lock_class *class;unsigned long idx; -char c;if (count) { -if (get_user (c, buf)) -return -EFAULT ; - -if (c !='0' ) +if (buf[0 ] !='0' )return count; iterate_lock_classes(idx, class) {
@@ -703,7 +699,7 @@ static int lock_stat_release(struct inode *inode, struct file *file)static const struct proc_ops lock_stat_proc_ops = { .proc_seq_ops = &lockstat_ops, .proc_open = lock_stat_open, - .proc_write = lock_stat_write, + .proc_write_buf = lock_stat_write, .proc_release = lock_stat_release, };#endif /* CONFIG_LOCK_STAT */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 13/30] locking/lockdep: let procfs copy in writes to /proc/lock_stat
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and look at the first character of that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Christian Brauner
maintainerPATCH RESEND v2 14/30 profiling: let procfs copy in writes to /proc/profile
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and take the multiplier from that copy. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- kernel/profile.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
kernel/profile.c +4 -6
@@ -189,16 +189,14 @@ int __weak setup_profiling_timer(unsigned mult)* Writing a 'profiling multiplier' value into it also re-sets the profiling * interrupt frequency, on architectures that support this. */ -static ssize_t write_profile (struct file *file,const char __user *buf, -size_t count,loff_t *ppos) +static ssize_t write_profile (struct file *file,char *buf,size_t count, +loff_t *ppos) {#ifdef CONFIG_SMP if (count ==sizeof (int )) {unsigned int multiplier; -if (copy_from_user (&multiplier, buf,sizeof (int ))) -return -EFAULT ; - +memcpy (&multiplier, buf,sizeof (int ));if (setup_profiling_timer (multiplier))return -EINVAL ; }
@@ -209,7 +207,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,static const struct proc_ops profile_proc_ops = { .proc_read = read_profile, - .proc_write = write_profile, + .proc_write_buf = write_profile, .proc_lseek = default_llseek, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 14/30] profiling: let procfs copy in writes to /proc/profile
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Implement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and take the multiplier from that copy. Writes larger than
PAGE_SIZE- 1 bytes fail with-EINVALnow.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
Christian Brauner
maintainerPATCH RESEND v2 15/30 profiling: let procfs copy out reads of /proc/profile
In reply to Christian BraunerFill the buffer procfs hands to ->proc_read_buf() instead of reading straight into userspace. readprofile reads the whole file in one go, so ask for PROC_ENTRY_FULL_READS and procfs fills such a read in pieces. The file is read through ->read_iter() now, so sendfile() and splice() work on it like on the other converted entries.
--- kernel/profile.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/profile.c +5 -7
@@ -142,7 +142,6 @@ void profile_tick(int type)#ifdef CONFIG_PROC_FS #include <linux/proc_fs.h> #include <linux/seq_file.h> -#include <linux/uaccess.h> /* * This function accesses profiling information. The returned data is
@@ -151,7 +150,7 @@ void profile_tick(int type)* get meaningful info out of these data. */ static ssize_t -read_profile (struct file *file,char __user *buf,size_t count,loff_t *ppos) +read_profile (struct file *file,char *buf,size_t count,loff_t *ppos) {unsigned long p = *ppos;ssize_t read;
@@ -165,13 +164,11 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos) read =0 ;while (p <sizeof (unsigned int ) && count >0 ) { -if (put_user (*((char *)(&sample_step)+p), buf)) -return -EFAULT ; + *buf = *((char *)(&sample_step)+p); buf++; p++; count--; read++; } pnt = (char *)prof_buffer + p -sizeof (atomic_t); -if (copy_to_user (buf, (void *)pnt, count)) -return -EFAULT ; +memcpy (buf, pnt, count); read += count; *ppos += read;return read;
@@ -206,7 +203,8 @@ static ssize_t write_profile(struct file *file, char *buf, size_t count, }static const struct proc_ops profile_proc_ops = { - .proc_read = read_profile, + .proc_flags =PROC_ENTRY_FULL_READS , + .proc_read_buf = read_profile, .proc_write_buf = write_profile, .proc_lseek = default_llseek, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 15/30] profiling: let procfs copy out reads of /proc/profile
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
Fill the buffer procfs hands to ->proc_read_buf() instead of reading straight into userspace. readprofile reads the whole file in one go, so ask for
PROC_ENTRY_FULL_READSand procfs fills such a read in pieces. The file is read through ->read_iter() now, sosendfile()andsplice()work on it like on the other converted entries.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Christian Brauner
maintainerPATCH RESEND v2 16/30 profiling: mark /proc/profile permanent
In reply to Christian Brauner/proc/profile is created when profiling is turned on and never removed. Say so with PROC_ENTRY_PERMANENT, procfs then calls into it without pinning it.
--- kernel/profile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/profile.c +1 -1
@@ -203,7 +203,7 @@ static ssize_t write_profile(struct file *file, char *buf, size_t count, }static const struct proc_ops profile_proc_ops = { - .proc_flags =PROC_ENTRY_FULL_READS , + .proc_flags =PROC_ENTRY_PERMANENT |PROC_ENTRY_FULL_READS , .proc_read_buf = read_profile, .proc_write_buf = write_profile, .proc_lseek = default_llseek,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 16/30] profiling: mark /proc/profile permanent
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
/proc/profileis created when profiling is turned on and never removed. Say so withPROC_ENTRY_PERMANENT, procfs then calls into it without pinning it.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Christian Brauner
maintainerPATCH RESEND v2 17/30 sched/psi: let procfs own the seq_file of the pressure files
In reply to Christian BraunerDeclare the show functions and let procfs open and free the seq_file of /proc/pressure/*. That makes the open functions unnecessary and ->proc_release() only destroys the trigger now.
--- kernel/sched/psi.c | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-)
kernel/sched/psi.c +5 -33
@@ -1535,21 +1535,6 @@ static int psi_cpu_show(struct seq_file *m, void *v)return psi_show (m, &psi_system,PSI_CPU ); } -static int psi_io_open (struct inode *inode,struct file *file) -{ -return single_open (file, psi_io_show,NULL ); -} - -static int psi_memory_open (struct inode *inode,struct file *file) -{ -return single_open (file, psi_memory_show,NULL ); -} - -static int psi_cpu_open (struct inode *inode,struct file *file) -{ -return single_open (file, psi_cpu_show,NULL ); -} -static ssize_t psi_write (struct file *file,const char __user *user_buf,size_t nbytes,enum psi_res res) {
@@ -1635,31 +1620,25 @@ static int psi_fop_release(struct inode *inode, struct file *file)struct seq_file *seq = file->private_data;psi_trigger_destroy (seq->private); -return single_release (inode, file); +return 0 ; }static const struct proc_ops psi_io_proc_ops = { - .proc_open = psi_io_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, + .proc_show = psi_io_show, .proc_write = psi_io_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release, };static const struct proc_ops psi_memory_proc_ops = { - .proc_open = psi_memory_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, + .proc_show = psi_memory_show, .proc_write = psi_memory_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release, };static const struct proc_ops psi_cpu_proc_ops = { - .proc_open = psi_cpu_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, + .proc_show = psi_cpu_show, .proc_write = psi_cpu_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release,
@@ -1671,11 +1650,6 @@ static int psi_irq_show(struct seq_file *m, void *v)return psi_show (m, &psi_system,PSI_IRQ ); } -static int psi_irq_open (struct inode *inode,struct file *file) -{ -return single_open (file, psi_irq_show,NULL ); -} -static ssize_t psi_irq_write (struct file *file,const char __user *user_buf,size_t nbytes,loff_t *ppos) {
@@ -1683,9 +1657,7 @@ static ssize_t psi_irq_write(struct file *file, const char __user *user_buf, }static const struct proc_ops psi_irq_proc_ops = { - .proc_open = psi_irq_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, + .proc_show = psi_irq_show, .proc_write = psi_irq_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 17/30] sched/psi: let procfs own the seq_file of the pressure files
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Declare the show functions and let procfs open and free the
seq_fileof/proc/pressure/*. That makes the open functions unnecessary and ->proc_release() only destroys the trigger now.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Christian Brauner
maintainerPATCH RESEND v2 18/30 sched/psi: let procfs copy in trigger writes
In reply to Christian BraunerImplement ->proc_write_buf() for the files in /proc/pressure so procfs copies in what is written before it pins the entry, and take the trigger from that copy. Only the first 31 bytes were ever looked at. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- kernel/sched/psi.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-)
kernel/sched/psi.c +19 -21
@@ -1535,8 +1535,8 @@ static int psi_cpu_show(struct seq_file *m, void *v)return psi_show (m, &psi_system,PSI_CPU ); } -static ssize_t psi_write (struct file *file,const char __user *user_buf, -size_t nbytes,enum psi_res res) +static ssize_t psi_write (struct file *file,const char *kbuf,size_t nbytes, +enum psi_res res) {char buf[32 ];size_t buf_size;
@@ -1552,9 +1552,7 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf,return -EINVAL ; buf_size =min (nbytes,sizeof (buf) -1 ); -if (copy_from_user (buf, user_buf, buf_size)) -return -EFAULT ; - +memcpy (buf, kbuf, buf_size); buf[buf_size] ='\0' ; seq = file->private_data;
@@ -1590,22 +1588,22 @@ static ssize_t psi_write(struct file *file, const char __user *user_buf,return nbytes; } -static ssize_t psi_io_write (struct file *file,const char __user *user_buf, -size_t nbytes,loff_t *ppos) +static ssize_t psi_io_write (struct file *file,char *buf,size_t nbytes, +loff_t *ppos) { -return psi_write (file, user_buf, nbytes,PSI_IO ); +return psi_write (file, buf, nbytes,PSI_IO ); } -static ssize_t psi_memory_write (struct file *file,const char __user *user_buf, -size_t nbytes,loff_t *ppos) +static ssize_t psi_memory_write (struct file *file,char *buf,size_t nbytes, +loff_t *ppos) { -return psi_write (file, user_buf, nbytes,PSI_MEM ); +return psi_write (file, buf, nbytes,PSI_MEM ); } -static ssize_t psi_cpu_write (struct file *file,const char __user *user_buf, -size_t nbytes,loff_t *ppos) +static ssize_t psi_cpu_write (struct file *file,char *buf,size_t nbytes, +loff_t *ppos) { -return psi_write (file, user_buf, nbytes,PSI_CPU ); +return psi_write (file, buf, nbytes,PSI_CPU ); }static __poll_t psi_fop_poll (struct file *file,poll_table *wait)
@@ -1625,21 +1623,21 @@ static int psi_fop_release(struct inode *inode, struct file *file)static const struct proc_ops psi_io_proc_ops = { .proc_show = psi_io_show, - .proc_write = psi_io_write, + .proc_write_buf = psi_io_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release, };static const struct proc_ops psi_memory_proc_ops = { .proc_show = psi_memory_show, - .proc_write = psi_memory_write, + .proc_write_buf = psi_memory_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release, };static const struct proc_ops psi_cpu_proc_ops = { .proc_show = psi_cpu_show, - .proc_write = psi_cpu_write, + .proc_write_buf = psi_cpu_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release, };
@@ -1650,15 +1648,15 @@ static int psi_irq_show(struct seq_file *m, void *v)return psi_show (m, &psi_system,PSI_IRQ ); } -static ssize_t psi_irq_write (struct file *file,const char __user *user_buf, -size_t nbytes,loff_t *ppos) +static ssize_t psi_irq_write (struct file *file,char *buf,size_t nbytes, +loff_t *ppos) { -return psi_write (file, user_buf, nbytes,PSI_IRQ ); +return psi_write (file, buf, nbytes,PSI_IRQ ); }static const struct proc_ops psi_irq_proc_ops = { .proc_show = psi_irq_show, - .proc_write = psi_irq_write, + .proc_write_buf = psi_irq_write, .proc_poll = psi_fop_poll, .proc_release = psi_fop_release, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 18/30] sched/psi: let procfs copy in trigger writes
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_write_buf() for the files in
/proc/pressureso procfs copies in what is written before it pins the entry, and take the trigger from that copy. Only the first 31 bytes were ever looked at. Writes larger thanPAGE_SIZE- 1 bytes fail with-EINVALnow.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
Christian Brauner
maintainerPATCH RESEND v2 19/30 sched/psi: mark the pressure files permanent
In reply to Christian Brauner/proc/pressure/* are created when psi initializes and never removed. Say so with PROC_ENTRY_PERMANENT, procfs then calls into them without pinning them, like it does for /proc/profile.
That also takes care of a rule the files bent. psi_write() takes the seq_file's lock to serialize the triggers. A reader holds that lock while it copies to userspace, and now that procfs owns the seq_file it does that with the entry unpinned. So nothing that runs with the entry pinned may wait for that lock, and psi_write() ran pinned. Nothing ever waited for it since the files are never removed, but with the files permanent nothing runs pinned at all.
--- kernel/sched/psi.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/sched/psi.c +4 -0
@@ -1622,6 +1622,7 @@ static int psi_fop_release(struct inode *inode, struct file *file) }static const struct proc_ops psi_io_proc_ops = { + .proc_flags =PROC_ENTRY_PERMANENT , .proc_show = psi_io_show, .proc_write_buf = psi_io_write, .proc_poll = psi_fop_poll,
@@ -1629,6 +1630,7 @@ static const struct proc_ops psi_io_proc_ops = { };static const struct proc_ops psi_memory_proc_ops = { + .proc_flags =PROC_ENTRY_PERMANENT , .proc_show = psi_memory_show, .proc_write_buf = psi_memory_write, .proc_poll = psi_fop_poll,
@@ -1636,6 +1638,7 @@ static const struct proc_ops psi_memory_proc_ops = { };static const struct proc_ops psi_cpu_proc_ops = { + .proc_flags =PROC_ENTRY_PERMANENT , .proc_show = psi_cpu_show, .proc_write_buf = psi_cpu_write, .proc_poll = psi_fop_poll,
@@ -1655,6 +1658,7 @@ static ssize_t psi_irq_write(struct file *file, char *buf, size_t nbytes, }static const struct proc_ops psi_irq_proc_ops = { + .proc_flags =PROC_ENTRY_PERMANENT , .proc_show = psi_irq_show, .proc_write_buf = psi_irq_write, .proc_poll = psi_fop_poll,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 19/30] sched/psi: mark the pressure files permanent
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines
/proc/pressure/*are created when psi initializes and never removed. Say so withPROC_ENTRY_PERMANENT, procfs then calls into them without pinning them, like it does for/proc/profile.That also takes care of a rule the files bent.
psi_write()takes the seq_file's lock to serialize the triggers. A reader holds that lock while it copies to userspace, and now that procfs owns theseq_fileit does that with the entry unpinned. So nothing that runs with the entry pinned may wait for that lock, andpsi_write()ran pinned. Nothing ever waited for it since the files are never removed, but with the files permanent nothing runs pinned at all.
Quoted 1 line
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
Christian Brauner
maintainerPATCH RESEND v2 20/30 sched/psi: let procfs own the wait queue of the pressure files
In reply to Christian BraunerA trigger on one of the /proc/pressure files has a wait queue of its own for its poller, the cgroup pressure files use the queue of their kernfs node through kernfs_generic_poll() and kernfs_notify(). procfs owns the queue of its pressure files now, so use it the same way: the poll_wait() is procfs', and a trigger that fires wakes the pollers of its file with proc_poll_notify(). Like for the cgroup files every poller of the file is woken when any trigger on it fires, and each reports the state of its own trigger. psi_trigger_poll() doesn't need the file anymore.
--- include/linux/psi.h | 3 +-- include/linux/psi_types.h | 8 +++++--- kernel/cgroup/cgroup.c | 2 +- kernel/sched/psi.c | 30 +++++++++++++++++------------- 4 files changed, 24 insertions(+), 19 deletions(-)
include/linux/psi.h +1 -2
@@ -30,8 +30,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,int psi_trigger_create_rtpoll_worker (struct psi_group *group);void psi_trigger_destroy (struct psi_trigger *t); -__poll_t psi_trigger_poll (void **trigger_ptr,struct file *file, -poll_table *wait); +__poll_t psi_trigger_poll (void **trigger_ptr,poll_table *wait);#ifdef CONFIG_CGROUPS static inline struct psi_group *cgroup_psi (struct cgroup *cgrp)
include/linux/psi_types.h +5 -3
@@ -8,6 +8,8 @@#include <linux/kref.h> #include <linux/wait.h> +struct proc_dir_entry ; +#ifdef CONFIG_PSI /* Tracked task states */
@@ -132,12 +134,12 @@ struct psi_trigger {/* Backpointer needed during trigger destruction */ struct psi_group *group; -/* Wait queue for polling */ -wait_queue_head_t event_wait; -/* Kernfs file for cgroup triggers */ struct kernfs_open_file *of; +/* /proc/pressure file for system triggers, see proc_poll_notify() */ +struct proc_dir_entry *pde; +/* Pending event flag */ int event;
kernel/cgroup/cgroup.c +1 -1
@@ -4232,7 +4232,7 @@ static __poll_t cgroup_pressure_poll(struct kernfs_open_file *of, {struct cgroup_file_ctx *ctx = of->priv; -return psi_trigger_poll (&ctx->psi.trigger, of->file, pt); +return psi_trigger_poll (&ctx->psi.trigger, pt); }static void cgroup_pressure_release (struct kernfs_open_file *of)
kernel/sched/psi.c +17 -13
@@ -514,7 +514,7 @@ static void update_triggers(struct psi_group *group, u64 now,if (t->of)kernfs_notify (t->of->kn);else -wake_up_interruptible (&t->event_wait); +proc_poll_notify (t->pde); } t->last_event_time = now;/* Reset threshold breach flag once event got generated */
@@ -1327,6 +1327,9 @@ int psi_trigger_create_rtpoll_worker(struct psi_group *group)return 0 ; } +/* the /proc/pressure files, see psi_proc_init() */ +static struct proc_dir_entry *psi_proc_entry[NR_PSI_RESOURCES ]; + struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf, enum psi_res res, struct file *file, struct kernfs_open_file *of,
@@ -1392,8 +1395,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf, t->event =0 ; t->last_event_time =0 ; t->of = of; -if (!of) -init_waitqueue_head (&t->event_wait); + t->pde = of ?NULL : psi_proc_entry[res]; t->pending_event = false; t->aggregator = privileged ?PSI_POLL :PSI_AVGS ;
@@ -1441,7 +1443,7 @@ void psi_trigger_destroy(struct psi_trigger *t)if (t->of)kernfs_notify (t->of->kn);else -wake_up_interruptible (&t->event_wait); +proc_poll_notify (t->pde);if (t->aggregator ==PSI_AVGS ) {mutex_lock (&group->avgs_lock);
@@ -1495,8 +1497,7 @@ void psi_trigger_destroy(struct psi_trigger *t)kfree (t); } -__poll_t psi_trigger_poll (void **trigger_ptr, -struct file *file,poll_table *wait) +__poll_t psi_trigger_poll (void **trigger_ptr,poll_table *wait) {__poll_t ret =DEFAULT_POLLMASK ;struct psi_trigger *t;
@@ -1508,10 +1509,9 @@ __poll_t psi_trigger_poll(void **trigger_ptr,if (!t)return DEFAULT_POLLMASK |EPOLLERR |EPOLLPRI ; +/* a /proc/pressure file is polled on the queue procfs owns for it */ if (t->of)kernfs_generic_poll (t->of, wait); -else -poll_wait (file, &t->event_wait, wait);if (cmpxchg (&t->event,1 ,0 ) ==1 ) ret |=EPOLLPRI ;
@@ -1610,7 +1610,7 @@ static __poll_t psi_fop_poll(struct file *file, poll_table *wait) {struct seq_file *seq = file->private_data; -return psi_trigger_poll (&seq->private, file, wait); +return psi_trigger_poll (&seq->private, wait); }static int psi_fop_release (struct inode *inode,struct file *file)
@@ -1670,11 +1670,15 @@ static int __init psi_proc_init(void) {if (psi_enable) {proc_mkdir ("pressure" ,NULL ); -proc_create ("pressure/io" ,0666 ,NULL , &psi_io_proc_ops); -proc_create ("pressure/memory" ,0666 ,NULL , &psi_memory_proc_ops); -proc_create ("pressure/cpu" ,0666 ,NULL , &psi_cpu_proc_ops); + psi_proc_entry[PSI_IO ] =proc_create ("pressure/io" ,0666 ,NULL , + &psi_io_proc_ops); + psi_proc_entry[PSI_MEM ] =proc_create ("pressure/memory" ,0666 , +NULL , &psi_memory_proc_ops); + psi_proc_entry[PSI_CPU ] =proc_create ("pressure/cpu" ,0666 ,NULL , + &psi_cpu_proc_ops);#ifdef CONFIG_IRQ_TIME_ACCOUNTING -proc_create ("pressure/irq" ,0666 ,NULL , &psi_irq_proc_ops); + psi_proc_entry[PSI_IRQ ] =proc_create ("pressure/irq" ,0666 ,NULL , + &psi_irq_proc_ops);#endif }return 0 ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 20/30] sched/psi: let procfs own the wait queue of the pressure files
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
A trigger on one of the
/proc/pressurefiles has a wait queue of its own for its poller, the cgroup pressure files use the queue of their kernfs node throughkernfs_generic_poll()andkernfs_notify(). procfs owns the queue of its pressure files now, so use it the same way: thepoll_wait()is procfs', and a trigger that fires wakes the pollers of its file withproc_poll_notify(). Like for the cgroup files every poller of the file is woken when any trigger on it fires, and each reports the state of its own trigger.psi_trigger_poll()doesn't need the file anymore.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
Christian Brauner
maintainerPATCH RESEND v2 21/30 kallsyms: let procfs own the seq_file of /proc/kallsyms
In reply to Christian BraunerDeclare the seq_operations and the size of the iterator and let procfs open and free the seq_file. ->proc_open() only initializes the iterator now.
--- kernel/kallsyms.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
kernel/kallsyms.c +5 -7
@@ -888,10 +888,9 @@ static int kallsyms_open(struct inode *inode, struct file *file)* s_start from where we left off, so we avoid doing * using get_symbol_offset for every symbol. */ -struct kallsym_iter *iter; - iter =__seq_open_private (file, &kallsyms_op,sizeof (*iter)); -if (!iter) -return -ENOMEM ; +struct seq_file *m = file->private_data; +struct kallsym_iter *iter = m->private; +reset_iter (iter,0 );/*
@@ -923,10 +922,9 @@ const char *kdb_walk_kallsyms(loff_t *pos)#endif /* CONFIG_KGDB_KDB */ static const struct proc_ops kallsyms_proc_ops = { + .proc_seq_ops = &kallsyms_op, + .proc_state_size =sizeof (struct kallsym_iter ), .proc_open = kallsyms_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = seq_release_private, };static int __init kallsyms_init (void )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 21/30] kallsyms: let procfs own the seq_file of /proc/kallsyms
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Declare the
seq_operationsand the size of the iterator and let procfs open and free theseq_file. ->proc_open() only initializes the iterator now.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Christian Brauner
maintainerPATCH RESEND v2 22/30 module: procfs: let procfs own the seq_file of /proc/modules
In reply to Christian BraunerDeclare the seq_operations and let procfs open and free the seq_file. ->proc_open() only decides whether to hide the addresses now.
--- kernel/module/procfs.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
kernel/module/procfs.c +6 -13
@@ -117,31 +117,24 @@ static const struct seq_operations modules_op = { };/* -* This also sets the "private" pointer to non-NULL if the -* kernel pointers should be hidden (so you can just test +* procfs opens the seq_file. This sets the "private" pointer to non-NULL +* if the kernel pointers should be hidden (so you can just test * "m->private" to see if you should keep the values private). * * We use the same logic as for /proc/kallsyms. */ static int modules_open (struct inode *inode,struct file *file) { -int err =seq_open (file, &modules_op); +struct seq_file *m = file->private_data; -if (!err) { -struct seq_file *m = file->private_data; - - m->private =kallsyms_show_value (file->f_cred) ?NULL : (void *)8ul ; - } - -return err; + m->private =kallsyms_show_value (file->f_cred) ?NULL : (void *)8ul ; +return 0 ; }static const struct proc_ops modules_proc_ops = { .proc_flags =PROC_ENTRY_PERMANENT , + .proc_seq_ops = &modules_op, .proc_open = modules_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = seq_release, };static int __init proc_modules_init (void )
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 22/30] module: procfs: let procfs own the seq_file of /proc/modules
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Declare the
seq_operationsand let procfs open and free theseq_file. ->proc_open() only decides whether to hide the addresses now.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
Christian Brauner
maintainerPATCH RESEND v2 23/30 dyndbg: let procfs copy in writes to /proc/dynamic_debug/control
In reply to Christian BraunerMove the parsing into ddebug_proc_write_buf() and implement ->proc_write_buf() with it so procfs copies in what is written before it pins the entry. The debugfs file keeps copying in itself. Writes larger than USER_BUF_PAGE - 1 bytes to the procfs file now fail with -EINVAL from procfs instead of -E2BIG, and without the "expected <4096 bytes into control" warning.
--- lib/dynamic_debug.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
lib/dynamic_debug.c +22 -12
@@ -1002,11 +1002,28 @@ __setup("dyndbg=", dyndbg_setup);* command text from userspace, parses and executes it. */ #define USER_BUF_PAGE 4096 + +static ssize_t ddebug_proc_write_buf (struct file *file,char *buf,size_t len, +loff_t *offp) +{ +int ret; + +if (len ==0 ) +return 0 ; +v2pr_info ("read %zu bytes from userspace\n" , len); + + ret =ddebug_exec_queries (buf,NULL ); +if (ret <0 ) +return ret; + + *offp += len; +return len; +} +static ssize_t ddebug_proc_write (struct file *file,const char __user *ubuf,size_t len,loff_t *offp) { -char *tmpbuf; -int ret; + char *tmpbuf __free(kfree) = NULL;if (len ==0 )return 0 ;
@@ -1017,15 +1034,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, tmpbuf =memdup_user_nul (ubuf, len);if (IS_ERR (tmpbuf))return PTR_ERR (tmpbuf); -v2pr_info ("read %zu bytes from userspace\n" , len); - - ret =ddebug_exec_queries (tmpbuf,NULL ); -kfree (tmpbuf); -if (ret <0 ) -return ret; - - *offp += len; -return len; +return ddebug_proc_write_buf (file, tmpbuf, len, offp); }/*
@@ -1196,7 +1205,8 @@ static const struct file_operations ddebug_proc_fops = {static const struct proc_ops proc_fops = { .proc_seq_ops = &ddebug_proc_seqops, .proc_state_size =sizeof (struct ddebug_iter ), - .proc_write = ddebug_proc_write + .proc_write_buf = ddebug_proc_write_buf, + .proc_write_size =USER_BUF_PAGE -1 , }; static void ddebug_attach_module_classes(struct ddebug_table *dt,
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 23/30] dyndbg: let procfs copy in writes to /proc/dynamic_debug/control
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dyndbg: split declaration and assignment of __free() in ddebug_proc_write() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dyndbg: split declaration and assignment of __free() in ddebug_proc_write() --
commit 1bfaabab91de2989a4d10ae03eef349ab77809d6
Author: Christian Brauner <[email protected]>
dyndbg: let procfs copy in writes to /proc/dynamic_debug/control
This commit factors the query execution logic out of ddebug_proc_write() into ddebug_proc_write_buf() and switches proc_fops to use .proc_write_buf and .proc_write_size so procfs copies in the user buffer before pinning the entry.
Quoted 5 lines
lib/dynamic_debug.c +0
-0@@ -1002,11 +1002,28 @@ __setup("dyndbg=", dyndbg_setup);
[ ... ]
Quoted 14 lines
static
ssize_tddebug_proc_write(struct file *file, const char__user*ubuf,lib/dynamic_debug.c +1
-3size_t len, loff_t *offp) { - char *tmpbuf; -int ret; + char *tmpbuf __free(kfree) = NULL;if (len ==0 )return 0 ;@@ -1017,15 +1034,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, tmpbuf =memdup_user_nul (ubuf, len);if (IS_ERR (tmpbuf))return PTR_ERR (tmpbuf); -v2pr_info ("read %zu bytes from userspace\n" , len);
lib/dynamic_debug.c static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, · line 1038
Quoted 10 lines
lib/dynamic_debug.c +1
-8- - ret =ddebug_exec_queries (tmpbuf,NULL ); -kfree (tmpbuf); -if (ret <0 ) -return ret; - - *offp += len; -return len; +return ddebug_proc_write_buf (file, tmpbuf, len, offp); }
[Severity: Low]
In ddebug_proc_write(), tmpbuf is declared with __free(kfree) = NULL at the top of the function before the early length checks and then assigned later via memdup_user_nul().
Per the cleanup.h guidelines, could tmpbuf be defined and initialized in a single statement at the allocation site instead:
char *tmpbuf __free(kfree) = memdup_user_nul(ubuf, len);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
Christian Brauner
maintainerPATCH RESEND v2 24/30 ipc: let procfs own the seq_file of the sysvipc files
In reply to Christian BraunerDeclare the seq_operations and the size of the iterator and let procfs open and free the seq_file of /proc/sysvipc/*. ->proc_open() only fills in the iterator now and ->proc_release() drops the references it holds.
--- ipc/util.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
ipc/util.c +6 -8
@@ -894,13 +894,11 @@ static const struct seq_operations sysvipc_proc_seqops = { .show = sysvipc_proc_show, }; +/* procfs opened the seq_file and allocated @iter */ static int sysvipc_proc_open (struct inode *inode,struct file *file) { -struct ipc_proc_iter *iter; - - iter =__seq_open_private (file, &sysvipc_proc_seqops,sizeof (*iter)); -if (!iter) -return -ENOMEM ; +struct seq_file *m = file->private_data; +struct ipc_proc_iter *iter = m->private; iter->iface =pde_data (inode); iter->ns =get_ipc_ns (current->nsproxy->ipc_ns);
@@ -915,14 +913,14 @@ static int sysvipc_proc_release(struct inode *inode, struct file *file)struct ipc_proc_iter *iter = seq->private;put_ipc_ns (iter->ns);put_pid_ns (iter->pid_ns); - return seq_release_private(inode, file); + return 0; }static const struct proc_ops sysvipc_proc_ops = { .proc_flags =PROC_ENTRY_PERMANENT , + .proc_seq_ops = &sysvipc_proc_seqops, + .proc_state_size =sizeof (struct ipc_proc_iter ), .proc_open = sysvipc_proc_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_release = sysvipc_proc_release, };#endif /* CONFIG_PROC_FS */
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 24/30] ipc: let procfs own the seq_file of the sysvipc files
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Declare the
seq_operationsand the size of the iterator and let procfs open and free theseq_fileof/proc/sysvipc/*. ->proc_open() only fills in the iterator now and ->proc_release() drops the references it holds.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
Christian Brauner
maintainerPATCH RESEND v2 25/30 alloc_tag: let procfs own the seq_file of /proc/allocinfo
In reply to Christian BraunerDeclare the seq_operations and the size of the private state and let procfs open and free the seq_file. ->proc_open() and ->proc_release() only set up and destroy the ioctl lock now.
--- mm/alloc_tag.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-)
mm/alloc_tag.c +11 -17
@@ -152,27 +152,21 @@ static const struct seq_operations allocinfo_seq_op = { };/* -* Initializes seq_file operations and allocates private state when opening -* the /proc/allocinfo procfs entry. +* Initializes the private state when opening the /proc/allocinfo procfs +* entry. procfs opened the seq_file and allocated the state. */ static int allocinfo_open (struct inode *inode,struct file *file) { -int ret; - - ret =seq_open_private (file, &allocinfo_seq_op, -sizeof (struct allocinfo_private )); -if (!ret) { -struct seq_file *m = file->private_data; -struct allocinfo_private *priv = m->private; +struct seq_file *m = file->private_data; +struct allocinfo_private *priv = m->private; -mutex_init (&priv->ioctl_lock); - } -return ret; +mutex_init (&priv->ioctl_lock); +return 0 ; }/* -* Cleans up the seq_file state and frees up the private state allocated in -* allocinfo_open() when closing the /proc/allocinfo file descriptor. +* Undoes allocinfo_open() when closing the /proc/allocinfo file descriptor. +* procfs frees the seq_file and the private state. */ static int allocinfo_release (struct inode *inode,struct file *file) {
@@ -180,7 +174,7 @@ static int allocinfo_release(struct inode *inode, struct file *file)struct allocinfo_private *priv = m->private;mutex_destroy (&priv->ioctl_lock); -return seq_release_private (inode, file); +return 0 ; }/*
@@ -475,9 +469,9 @@ static long allocinfo_compat_ioctl(struct file *file, unsigned int cmd,#endif static const struct proc_ops allocinfo_proc_ops = { + .proc_seq_ops = &allocinfo_seq_op, + .proc_state_size =sizeof (struct allocinfo_private ), .proc_open = allocinfo_open, - .proc_read_iter = seq_read_iter, - .proc_lseek = seq_lseek, .proc_release = allocinfo_release, .proc_ioctl = allocinfo_ioctl, #ifdef CONFIG_COMPAT
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 25/30] alloc_tag: let procfs own the seq_file of /proc/allocinfo
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Declare the
seq_operationsand the size of the private state and let procfs open and free theseq_file. ->proc_open() and ->proc_release() only set up and destroy the ioctl lock now.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
Christian Brauner
maintainerPATCH RESEND v2 26/30 alloc_tag: let procfs copy the ioctl arguments of /proc/allocinfo
In reply to Christian BraunerImplement ->proc_ioctl_buf() so procfs copies the arguments in before it pins the entry and back out after unpinning it. The commands encode their arguments. procfs converts the pointers of 32-bit tasks, so allocinfo_compat_ioctl() goes away.
--- mm/alloc_tag.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-)
mm/alloc_tag.c +17 -30
@@ -6,7 +6,6 @@#include <linux/kallsyms.h> #include <linux/module.h> #include <linux/mutex.h> -#include <linux/compat.h> #include <linux/page_ext.h> #include <linux/pgalloc_tag.h> #include <linux/proc_fs.h>
@@ -236,16 +235,14 @@ static void allocinfo_to_params(struct codetag *ct,* Retrieves the unique content ID representing the current allocation tag module * layout, allowing userspace to detect if modules were loaded / unloaded. */ -static int allocinfo_ioctl_get_content_id (struct seq_file *m,void __user *arg) +static int allocinfo_ioctl_get_content_id (struct seq_file *m,void *arg) {struct allocinfo_content_id params;codetag_lock_module_list (alloc_tag_cttype); params.id =codetag_get_content_id (alloc_tag_cttype);codetag_unlock_module_list (alloc_tag_cttype); -if (copy_to_user (arg, ¶ms,sizeof (params))) -return -EFAULT ; - +memcpy (arg, ¶ms,sizeof (params));return 0 ; }
@@ -310,7 +307,7 @@ static bool matches_filter(struct codetag *ct, struct allocinfo_filter *filter,* Seeks the ioctl iterator to the specified 0-indexed tag position, reads its * profiling data and returns it to userspace. */ -static int allocinfo_ioctl_get_at (struct seq_file *m,void __user *arg) +static int allocinfo_ioctl_get_at (struct seq_file *m,void *arg) {struct allocinfo_private *priv;struct codetag *ct;
@@ -319,8 +316,7 @@ static int allocinfo_ioctl_get_at(struct seq_file *m, void __user *arg)struct alloc_tag_counters counters;bool fetched_counters; -if (copy_from_user (¶ms, arg,sizeof (params))) -return -EFAULT ; +memcpy (¶ms, arg,sizeof (params));if (params.filter.mask & ~ALLOCINFO_FILTER_MASKS )return -EINVAL ;
@@ -375,9 +371,7 @@ static int allocinfo_ioctl_get_at(struct seq_file *m, void __user *arg)if (!ct)return -ENOENT ; -if (copy_to_user (arg, ¶ms,sizeof (params))) -return -EFAULT ; - +memcpy (arg, ¶ms,sizeof (params));return 0 ; }
@@ -385,7 +379,7 @@ static int allocinfo_ioctl_get_at(struct seq_file *m, void __user *arg)* Advances the ioctl iterator to the next allocation tag in the sequence and * returns its profiling data to userspace. */ -static int allocinfo_ioctl_get_next (struct seq_file *m,void __user *arg) +static int allocinfo_ioctl_get_next (struct seq_file *m,void *arg) {struct allocinfo_private *priv;struct codetag *ct;
@@ -425,10 +419,8 @@ static int allocinfo_ioctl_get_next(struct seq_file *m, void __user *arg)codetag_unlock_module_list (alloc_tag_cttype);mutex_unlock (&priv->ioctl_lock); -if (ret ==0 ) { -if (copy_to_user (arg, ¶ms,sizeof (params))) -return -EFAULT ; - } +if (ret ==0 ) +memcpy (arg, ¶ms,sizeof (params));return ret; }
@@ -436,10 +428,8 @@ static int allocinfo_ioctl_get_next(struct seq_file *m, void __user *arg)* Entry point ioctl function for /proc/allocinfo routing requests to fetch the * layout content ID, seek to a specific tag, or read sequential tags. */ -static long allocinfo_ioctl (struct file *file,unsigned int cmd, -unsigned long __arg) +static long allocinfo_ioctl (struct file *file,unsigned int cmd,void *arg) { -void __user *arg = (void __user *)__arg;int ret;switch (cmd) {
@@ -460,23 +450,20 @@ static long allocinfo_ioctl(struct file *file, unsigned int cmd,return ret; } -#ifdef CONFIG_COMPAT -static long allocinfo_compat_ioctl (struct file *file,unsigned int cmd, -unsigned long arg) -{ -return allocinfo_ioctl (file, cmd, (unsigned long )compat_ptr (arg)); -} -#endif +static const struct proc_ioctl_arg allocinfo_ioctl_args[] = { +PROC_IOCTL_IOC (ALLOCINFO_IOC_CONTENT_ID ), +PROC_IOCTL_IOC (ALLOCINFO_IOC_GET_AT ), +PROC_IOCTL_IOC (ALLOCINFO_IOC_GET_NEXT ), +};static const struct proc_ops allocinfo_proc_ops = { .proc_seq_ops = &allocinfo_seq_op, .proc_state_size =sizeof (struct allocinfo_private ), .proc_open = allocinfo_open, .proc_release = allocinfo_release, - .proc_ioctl = allocinfo_ioctl, -#ifdef CONFIG_COMPAT - .proc_compat_ioctl = allocinfo_compat_ioctl, -#endif + .proc_ioctl_buf = allocinfo_ioctl, + .proc_ioctl_args = allocinfo_ioctl_args, + .proc_nr_ioctl_args =ARRAY_SIZE (allocinfo_ioctl_args), };size_t alloc_tag_top_users (struct codetag_bytes *tags,size_t count,bool can_sleep)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 26/30] alloc_tag: let procfs copy the ioctl arguments of /proc/allocinfo
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_ioctl_buf() so procfs copies the arguments in before it pins the entry and back out after unpinning it. The commands encode their arguments. procfs converts the pointers of 32-bit tasks, so
allocinfo_compat_ioctl()goes away.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
Christian Brauner
maintainerPATCH RESEND v2 27/30 mm/swapfile: let procfs own the seq_file of /proc/swaps
In reply to Christian BraunerDeclare the seq_operations and let procfs open and free the seq_file. ->proc_open() only records the event count for ->proc_poll() now.
--- mm/swapfile.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
mm/swapfile.c +3 -10
@@ -3410,26 +3410,19 @@ static const struct seq_operations swaps_op = { .show = swap_show }; +/* procfs opens the seq_file */ static int swaps_open (struct inode *inode,struct file *file) { -struct seq_file *seq; -int ret; - - ret =seq_open (file, &swaps_op); -if (ret) -return ret; +struct seq_file *seq = file->private_data; - seq = file->private_data; seq->poll_event =atomic_read (&proc_poll_event);return 0 ; }static const struct proc_ops swaps_proc_ops = { .proc_flags =PROC_ENTRY_PERMANENT , + .proc_seq_ops = &swaps_op, .proc_open = swaps_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, - .proc_release = seq_release, .proc_poll = swaps_poll, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 27/30] mm/swapfile: let procfs own the seq_file of /proc/swaps
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Declare the
seq_operationsand let procfs open and free theseq_file. ->proc_open() only records the event count for ->proc_poll() now.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
Christian Brauner
maintainerPATCH RESEND v2 28/30 mm/swapfile: let procfs own the wait queue of /proc/swaps
In reply to Christian Braunerswaps_poll() sleeps the poller on a queue of its own. procfs owns the queue poll() uses now, so leave the poll_wait() to it and wake its pollers when a swap area comes or goes.
--- mm/swapfile.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
mm/swapfile.c +4 -6
@@ -111,7 +111,7 @@ static struct kmem_cache *swap_table_cachep;/* Protects si->swap_file for /proc/swaps usage */ static DEFINE_MUTEX (swapon_mutex); -static DECLARE_WAIT_QUEUE_HEAD (proc_poll_wait); +static struct proc_dir_entry *proc_swaps;/* Activity counter to indicate that a swapon or swapoff has occurred */ static atomic_t proc_poll_event =ATOMIC_INIT (0 );
@@ -3307,7 +3307,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) err =0 ;atomic_inc (&proc_poll_event); -wake_up_interruptible (&proc_poll_wait); +proc_poll_notify (proc_swaps); out_dput:filp_close (victim,NULL );
@@ -3319,8 +3319,6 @@ static __poll_t swaps_poll(struct file *file, poll_table *wait) {struct seq_file *seq = file->private_data; -poll_wait (file, &proc_poll_wait, wait); -if (seq->poll_event !=atomic_read (&proc_poll_event)) { seq->poll_event =atomic_read (&proc_poll_event);return EPOLLIN |EPOLLRDNORM |EPOLLERR |EPOLLPRI ;
@@ -3428,7 +3426,7 @@ static const struct proc_ops swaps_proc_ops = {static int __init procswaps_init (void ) { -proc_create ("swaps" ,0 ,NULL , &swaps_proc_ops); + proc_swaps =proc_create ("swaps" ,0 ,NULL , &swaps_proc_ops);return 0 ; }__initcall (procswaps_init);
@@ -3907,7 +3905,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)mutex_unlock (&swapon_mutex);atomic_inc (&proc_poll_event); -wake_up_interruptible (&proc_poll_wait); +proc_poll_notify (proc_swaps); error =0 ; goto out;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 28/30] mm/swapfile: let procfs own the wait queue of /proc/swaps
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
swaps_poll()sleeps the poller on a queue of its own. procfs owns the queuepoll()uses now, so leave thepoll_wait()to it and wake its pollers when a swap area comes or goes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Christian Brauner
maintainerPATCH RESEND v2 29/30 kernel/configs: let procfs copy out reads of /proc/config.gz
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry. Unloading configs.ko then no longer waits for a reader that faults on its buffer. /proc/config.gz asks for PROC_ENTRY_FULL_READS so that reading all of it at once keeps working.
--- kernel/configs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/configs.c +4 -3
@@ -38,17 +38,18 @@ extern char kernel_config_data;extern char kernel_config_data_end;static ssize_t -ikconfig_read_current (struct file *file,char __user *buf, +ikconfig_read_current (struct file *file,char *buf,size_t len,loff_t * offset) { -return simple_read_from_buffer (buf, len, offset, +return memory_read_from_buffer (buf, len, offset, &kernel_config_data, &kernel_config_data_end - &kernel_config_data); }static const struct proc_ops config_gz_proc_ops = { - .proc_read = ikconfig_read_current, + .proc_flags =PROC_ENTRY_FULL_READS , + .proc_read_buf = ikconfig_read_current, .proc_lseek = default_llseek, };
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 29/30] kernel/configs: let procfs copy out reads of /proc/config.gz
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Implement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry. Unloading configs.ko then no longer waits for a reader that faults on its buffer.
/proc/config.gzasks forPROC_ENTRY_FULL_READSso that reading all of it at once keeps working.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Christian Brauner
maintainerPATCH RESEND v2 30/30 selftests/proc: check that unloading configs doesn't wait for a reader
In reply to Christian BraunerRead /proc/config.gz into a buffer whose first page is backed by userfaultfd and unload configs.ko while procfs copies what was read to userspace:
- removing the entry doesn't wait for the reader
- the reader still gets the page that was read before the removal, and nothing more
- and the next read fails with -EIO
The test loads configs.ko if it isn't there, skips if configs is built in or can't be unloaded, and loads it again afterwards. It needs CONFIG_IKCONFIG=m. kselftest-merge keeps the =y that other fragments ask for, so it skips there.
--- tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/config | 2 + .../proc/proc-remove-slow-config-reader.c | 157 +++++++++++++++++++++ 4 files changed, 161 insertions(+)
tools/testing/selftests/proc/.gitignore +1 -0
@@ -21,6 +21,7 @@ /proc-uptime-001 /proc-uptime-002 /proc-pidns +/proc-remove-slow-config-reader /proc-remove-slow-sysctl /proc-remove-slow-reader /proc-remove-mapped
tools/testing/selftests/proc/Makefile +1 -0
@@ -33,6 +33,7 @@ TEST_GEN_PROGS += proc-fsconfig-hidepid TEST_GEN_PROGS += proc-sysctl-readdir-churn TEST_GEN_PROGS += proc-pidns TEST_GEN_PROGS += proc-remove-slow-sysctl +TEST_GEN_PROGS += proc-remove-slow-config-reader TEST_GEN_PROGS += proc-remove-slow-reader TEST_GEN_PROGS += proc-remove-mapped TEST_GEN_PROGS += proc-remove-slow-readlink
tools/testing/selftests/proc/config +2 -0
@@ -11,3 +11,5 @@ CONFIG_SND=y CONFIG_SND_DUMMY=m CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y +CONFIG_IKCONFIG=m +CONFIG_IKCONFIG_PROC=y
tools/testing/selftests/proc/proc-remove-slow-config-reader.c new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RESEND v2 30/30] selftests/proc: check that unloading configs doesn't wait for a reader
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Read
/proc/config.gzinto a buffer whose first page is backed by userfaultfd and unload configs.ko while procfs copies what was read to userspace:- removing the entry doesn't wait for the reader
- the reader still gets the page that was read before the removal, and nothing more
Quoted 8 lines
- and the next read fails with
-EIOThe test loads configs.ko if it isn't there, skips if configs is built in or can't be unloaded, and loads it again afterwards. It needs
CONFIG_IKCONFIG=m. kselftest-merge keeps the =y that other fragments ask for, so it skips there.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
Re: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
In reply to Christian BraunerQuoted 2 lines · Christian Brauner
Part 5/7 of "proc: move procfs to what kernfs does", on top of part 2
Christian - way too many patches, re-sent much too often, cc'd to way too many people.
Nobody is going to read these repeated resends, and all you are doing is clogging up peoples mailboxes.
Linus
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 9 lines · Linus Torvalds
Quoted 2 lines · Christian Brauner
Part 5/7 of "proc: move procfs to what kernfs does", on top of part 2
Christian - way too many patches, re-sent much too often, cc'd to way too many people.
Nobody is going to read these repeated resends, and all you are doing is clogging up peoples mailboxes.
I resent once after I cleaned things up post RFC and I don't plan on resending (one failed attempt due to my network dropping).
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 2 lines
I resent once after I cleaned things up post RFC and I don't plan on resending (one failed attempt due to my network dropping).
A git tree with all of the patches can be found at:
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=work.procfs.cleanup
The overview is in the umbrella:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
Thanks!
Re: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 7 lines · Christian Brauner
Quoted 3 lines
I resent once after I cleaned things up post RFC and I don't plan on resending (one failed attempt due to my network dropping).
A git tree with all of the patches can be found at:
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=work.procfs.cleanup
Thanks. Looking at it again, I now reacted to the PCI proc_bus_pci_read() patch again, and decided that what I *really* hate about it is that it uses those "unsigned int" variables in the first place.
And even worse, proc_bus_pci_write() uses the signed "int" variables.
That's just wrong. It's all garbage. It shouldn't use "int" at all. I think it's just that all this code is two decades+ old, and 64-bit issues weren't a thing, and even "loff_t" was a newfangled interface at the time.
"pos" should just be loff_t, and "size" and "cnt" should be "size_t". Those are the correct types for those things. Not "unsigned int" and certainly not "int".
And yeah, cfg_size in "struct pci_dev" really is "int", and that's an independent issue and likely a bug in the PCI layer.
int pci_cfg_space_size(struct pci_dev *dev);
doesn't seem able to actually return signed values (I think it returns either 256 or 4096), but "int" is still not a great type for it - and the comparisons with proper variables like 'size_t' will then turn the comparison unsigned anyway.
This is all ancient code that works, but isn't pretty. But I'd rather fix the types than do things like
if (*ppos >= size)
return 0;
pos = *ppos;which first does the comparison in the right type before it then truncates it to the wrong one...
Linus
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 3 lines · Linus Torvalds
"pos" should just be
loff_t, and "size" and "cnt" should be "size_t". Those are the correct types for those things. Not "unsigned int" and certainly not "int".
Sounds good:
drivers/pci/proc.c +7 -4
@@ -32,7 +32,8 @@ size_t nbytes, loff_t *ppos) { struct pci_dev *dev = pde_data(file_inode(file)); -unsigned int pos, cnt, size; +loff_t pos; +size_t cnt, size;/* * Normal users can read only the standardized portion of the
@@ -119,8 +120,10 @@ {struct inode *ino =file_inode (file);struct pci_dev *dev =pde_data (ino); -int size = dev->cfg_size; -int pos, cnt, ret; +size_t size = dev->cfg_size; +loff_t pos; +size_t cnt; +int ret; ret =security_locked_down (LOCKDOWN_PCI_ACCESS );if (ret)
@@ -134,7 +137,7 @@ pos = *ppos;if (resource_is_exclusive (&dev->driver_exclusive_resource, pos, nbytes)) { -pci_warn_once (dev,"%s: Unexpected write to kernel-exclusive config offset %x" , +pci_warn_once (dev,"%s: Unexpected write to kernel-exclusive config offset %llx" , current->comm, pos);add_taint (TAINT_USER ,LOCKDEP_STILL_OK ); }
cfg_size stays an int in struct pci_dev, that's a larger thing.
Re: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
A git tree with all of the patches can be found at:
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=work.procfs.cleanup
Next comment: 3c7a6276d211 ("scsi: core: NUL-terminate what is written to the host proc files") is nasty.
It does compares 'count' to PROC_BLOCK_SIZE, and then after that it just allocates PAGE_SIZE and does
page[count] = '\0';
and it all *works*, but it depends on that PROC_BLOCK_SIZE being a random value smaller than PAGE_SIZE:
#define PROC_BLOCK_SIZE (3*1024)
and yes, the minimum page size we support across architectures is 4k.
So this is a "it works, but it's still wrong" kind of thing. If making changes in this area, please just fix these kinds of issues. Use the *same* constant for size comparisons rather than two different ones.
Linus
Re: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 3 lines · Linus Torvalds
It does compares 'count' to
PROC_BLOCK_SIZE, and then after that it just allocatesPAGE_SIZEand does
Ahh, this all goes away in "scsi: core: let procfs copy in writes", so never mind.
Linus
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 2 lines · Linus Torvalds
Ahh, this all goes away in "scsi: core: let procfs copy in writes", so never mind.
Yeah, but we can still do what you say in the fix:
drivers/scsi/scsi_proc.c +6 -11
@@ -66,24 +66,19 @@ size_t count, loff_t *ppos) { struct Scsi_Host *shost = pde_data(file_inode(file)); -ssize_t ret = -ENOMEM ; +ssize_t ret;char *page; - +if (count >PROC_BLOCK_SIZE )return -EOVERFLOW ;if (!shost->hostt->write_info)return -EINVAL ; - page =kmalloc (PAGE_SIZE ,GFP_KERNEL ); -if (page) { - ret = -EFAULT ; -if (copy_from_user (page, buf, count)) - goto out; - page[count] ='\0' ; - ret = shost->hostt->write_info (shost, page, count); - } -out: + page =memdup_user_nul (buf, count); +if (IS_ERR (page)) +return PTR_ERR (page); + ret = shost->hostt->write_info (shost, page, count);kfree (page);return ret; }
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 3 lines · Christian Brauner
Quoted 2 lines · Linus Torvalds
Ahh, this all goes away in "scsi: core: let procfs copy in writes", so never mind.
I updated the tree incorporating all the review items I acked on-list:
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=work.procfs.cleanup
The overview is in the umbrella:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 5 lines · Christian Brauner
Quoted 3 lines · Christian Brauner
Quoted 2 lines · Linus Torvalds
Ahh, this all goes away in "scsi: core: let procfs copy in writes", so never mind.
Quoted 7 lines
I updated the tree incorporating all the review items I acked on-list:
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=work.procfs.cleanup
The overview is in the umbrella:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
Oh, I think it'd be good if I get this into -next soon so it has long exposure there.
Christian Brauner
maintainerRe: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
Quoted 8 lines · Christian Brauner
Quoted 7 lines · Christian Brauner
Quoted 3 lines · Christian Brauner
Quoted 2 lines · Linus Torvalds
Ahh, this all goes away in "scsi: core: let procfs copy in writes", so never mind.
I updated the tree incorporating all the review items I acked on-list:
Quoted 8 lines
Quoted 5 lines
https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/log/?h=work.procfs.cleanup
The overview is in the umbrella:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@braunerOh, I think it'd be good if I get this into -next soon so it has long exposure there.
The bugfixes now sit in vfs.fixes and I plan to send them to you, @Linus before -rc4.
All of the semantic and tree-wide rework is in vfs-7.5.procfs and should show up in -next tomorrow.
Re: [PATCH RESEND v2 00/30] proc: convert the fs, kernel and mm entries (Part 5/7)
In reply to Linus TorvaldsQuoted 2 lines · On Fri, 6 Nov 2026 12:10:13 -0800 Linus Torvalds…
Next comment:
3c7a6276d211("scsi: core: NUL-terminate what is written to the host proc files") is nasty.
I've been looking at the similar sysfs code.
Most of the 'driver' functions are passed a char[PAGE_SIZE] buffer and use sysfs_emit() to add text.
They are expected to add the trailing '\n' - even though it is pretty much mandatory.
There is also a lot of code that loops:
offset += sysfs_emit_at(buf, offset, "%s, ", xxx);
and then has to go through horrid hoops to get the line terminated.
But the outer wrapper code can do it easily.
It has the buffer and length so can 'fiddle' with the end before telling the seq_buf code how much data is in the buffer.
I managed to build a kernel where the buf parameter to sysfs_emit() is a pointer to 'typedef struct { char c; } sysfs_buf'.
Pretty much all of the changes just changed the name of the type or replaced printf() with sysfs_emit().
Even with just 'typdef char sysfs_buf' it would be more obvious when sysfs_emit() was valid.
Don't look in the amdgpu driver it does:
off = buf & (PAGE - 1); buf -= off; sysfs_emit_at(buf, off, ....)
AFAICT it has proper aligned buffers - or my build would have failed.
I did find one disk related driver that copied (probably) 512 bytes of hex data into the buffer.
That is nasty, normal sysfs has the option of raw read/write, but they get lost by the time you are in the dev_xxx() functions.
OTOH the outer 'attr' structure has some padding (even on 32bit) so there is scope for some flags.
(There is one flag, but it gets set in the file permissions word which is all rather nasty.)
Then there is some of the raw code, I didn't follow it all through but it really looks like the user supplied length isn't checked properly.
For sub 4k buffers using the same code paths as text might make sense.
There is also the pre-alloc code added for some entries to avoid kmalloc() during reads by allocating a buffer during open.
Looking carefully the normal buffer is allocated during the first read but not freed until close - so it wouldn't be very different to just allocate it a little earlier, removing some other little-used code paths.
David
Christian Brauner
maintainerv2 cover proc: convert the net entries and the kfifo samples (Part 6/7)
In reply to Christian BraunerPart 6/7 of "proc: move procfs to what kernfs does", on top of part 2 and independent of parts 3 to 5:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
This converts the proc entries of atm, l2tp, pktgen, xt_recent and sunrpc, and the kfifo samples, to what "proc: let procfs own the data path" set up. Afterwards the entries' code only runs with the entry pinned and never touches userspace memory. One patch per subsystem and method.
- procfs owns the seq_file of /proc/net/pppol2tp, the xt_recent tables and the sunrpc cache content files. Their open and release hooks only take and drop references now, and reading an xt_recent table or a cache file no longer holds up its removal.
- procfs copies in the writes of pktgen, the xt_recent tables, the sunrpc channel, flush and use-gss-proxy files and the kfifo samples. The sunrpc channel files take 32k downcalls, which is what ->proc_write_size is for. Where a write larger than anything the entry parses now fails with -EINVAL from procfs the commit says so.
- procfs copies out the reads of the atm device files, the sunrpc channel, flush, use-gss-proxy and gss_krb5_enctypes files and the kfifo samples. The sunrpc channel and the kfifo samples are streams, they hand out what is read before procfs copies it out, so a reader that passes a bad buffer loses that part.
- the ioctl of the sunrpc channel files goes away, do_vfs_ioctl() answers FIONREAD for regular files before the file's ioctl ever sees it.
- the sunrpc channel files move their pollers to the wait queue procfs owns for the entry, which is what the static queue in the bugfix series stood in for. The rpc_pipefs channel files keep their queue_wait, procfs has nothing to do with them.
The selftest polls the channel file of a sunrpc cache in a network namespace of its own and lets the namespace die while the poller sleeps. On a KASAN and lockdep kernel it fails without the series, nothing wakes the poller and it times out after ten seconds, and passes with it. Build tested per commit on x86_64 and with W=1 on the touched objects. The pktgen selftest behaves the same with and without the series and so do the entries I could get at in a VM.
---
Changes in v2:
- sunrpc lets procfs own the wait queue of the channel files, which is
what the static queue_wait in the bugfix series stood in for
- new selftest: removing a polled entry wakes its pollers
- Acked-by from Chuck on the seq_file and ioctl patches
- the selftest commit applies on the core series alone
- rebased onto v7.4-rc1
- Link to v1: https://patch.msgid.link/[email protected]
---
Christian Brauner (13):
atm: let procfs copy out reads of the device files
l2tp: let procfs own the seq_file of /proc/net/pppol2tp
net: pktgen: let procfs copy in commands
netfilter: xt_recent: let procfs own the seq_file
netfilter: xt_recent: let procfs copy in writes
SUNRPC: let procfs own the seq_file of the cache content file
SUNRPC: let procfs copy in writes
SUNRPC: let procfs copy out reads
SUNRPC: drop the ioctl of the procfs channel files
SUNRPC: let procfs own the wait queue of the procfs channel files samples/kfifo: let procfs copy in writes
samples/kfifo: let procfs copy out reads
selftests/proc: check that removing a polled entry wakes its pollers
include/linux/sunrpc/cache.h | 2 + net/atm/proc.c | 9 +- net/core/pktgen.c | 128 ++++++--------- net/l2tp/l2tp_ppp.c | 20 +-- net/netfilter/xt_recent.c | 19 +-- net/sunrpc/auth_gss/svcauth_gss.c | 34 ++-- net/sunrpc/cache.c | 151 ++++++++++------- samples/kfifo/bytestream-example.c | 18 +-- samples/kfifo/inttype-example.c | 20 +-- samples/kfifo/record-example.c | 21 ++- tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/config | 2 + tools/testing/selftests/proc/proc-remove-polled.c | 189 ++++++++++++++++++++++ 14 files changed, 382 insertions(+), 233 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261101-work-procfs-net-bc8b21e3eff0
prerequisite-change-id: 20261101-work-procfs-core-8fa4a4f412cf:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
Christian Brauner
maintainerPATCH RESEND v2 1/13 atm: let procfs copy out reads of the device files
Implement ->proc_read_buf() so procfs copies what is read from /proc/net/atm/<dev> to userspace after it unpinned the entry. The drivers' ->proc_read() keep filling their page.
--- net/atm/proc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
net/atm/proc.c +4 -5
@@ -30,11 +30,11 @@#include "resources.h" #include "common.h" /* atm_proc_init prototype */ -static ssize_t proc_dev_atm_read (struct file *file,char __user *buf, +static ssize_t proc_dev_atm_read (struct file *file,char *buf,size_t count,loff_t *pos);static const struct proc_ops atm_dev_proc_ops = { - .proc_read = proc_dev_atm_read, + .proc_read_buf = proc_dev_atm_read, .proc_lseek = noop_llseek, };
@@ -246,7 +246,7 @@ static const struct seq_operations vcc_seq_ops = { .show = vcc_seq_show, }; -static ssize_t proc_dev_atm_read (struct file *file,char __user *buf, +static ssize_t proc_dev_atm_read (struct file *file,char *buf,size_t count,loff_t *pos) {struct atm_dev *dev;
@@ -267,8 +267,7 @@ static ssize_t proc_dev_atm_read(struct file *file, char __user *buf, length = -EINVAL ; }if (length >=0 ) { -if (copy_to_user (buf, (char *)page, length)) - length = -EFAULT ; +memcpy (buf, (char *)page, length); (*pos)++; }free_page (page);
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 2/13 l2tp: let procfs own the seq_file of /proc/net/pppol2tp
In reply to Christian BraunerDeclare the seq_operations and the size of the iterator state and let procfs open and free the seq_file. ->proc_open() only takes the reference to the network namespace now and ->proc_release() drops that and the references the iterator holds. Reading the file then no longer holds up its removal.
--- net/l2tp/l2tp_ppp.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
net/l2tp/l2tp_ppp.c +8 -12
@@ -1596,21 +1596,17 @@ static const struct seq_operations pppol2tp_seq_ops = { .show = pppol2tp_seq_show, }; +/* procfs opened the seq_file and allocated @pd */ static int pppol2tp_proc_open (struct inode *inode,struct file *file) { -struct net *net =pde_data (inode); -struct pppol2tp_seq_data *pd; +struct seq_file *seq = file->private_data; +struct pppol2tp_seq_data *pd__maybe_unused = seq->private; +struct net *net; - net =maybe_get_net (net); + net =maybe_get_net (pde_data (inode));if (!net)return -ENXIO ; - pd =__seq_open_private (file, &pppol2tp_seq_ops,sizeof (*pd)); -if (!pd) { -put_net (net); -return -ENOMEM ; - } -#ifdef CONFIG_NET_NS pd->p.net = net;netns_tracker_alloc (net, &pd->p.ns_tracker,GFP_KERNEL );
@@ -1633,13 +1629,13 @@ static int pppol2tp_proc_release(struct inode *inode, struct file *file)#else put_net (&init_net);#endif -return seq_release_private (inode, file); +return 0 ; }static const struct proc_ops pppol2tp_proc_ops = { + .proc_seq_ops = &pppol2tp_seq_ops, + .proc_state_size =sizeof (struct pppol2tp_seq_data ), .proc_open = pppol2tp_proc_open, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_release = pppol2tp_proc_release, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 3/13 net: pktgen: let procfs copy in commands
In reply to Christian BraunerImplement ->proc_write_buf() for the files in /proc/net/pktgen so procfs copies in what is written before it pins the entry, and parse the commands from that copy. The parse helpers read the copy instead of fetching every character with get_user(). Commands longer than PAGE_SIZE - 1 bytes fail with -EINVAL now.
With debug on, the dump of the command went through strndup_user() and failed the write with -EINVAL when there was no NUL right behind the command in the writer's buffer. The copy is NUL-terminated, so that's gone.
--- net/core/pktgen.c | 128 +++++++++++++++++++----------------------------------- 1 file changed, 45 insertions(+), 83 deletions(-)
net/core/pktgen.c +45 -83
@@ -516,11 +516,9 @@ static int pgctrl_show(struct seq_file *seq, void *v)return 0 ; } -static ssize_t pgctrl_write (struct file *file,const char __user *buf, -size_t count,loff_t *ppos) +static ssize_t pgctrl_write (struct file *file,char *buf,size_t count, +loff_t *ppos) { -char data[128 ]; -size_t max;struct pktgen_net *pn =net_generic (current->nsproxy->net_ns, pg_net_id);if (!capable (CAP_NET_ADMIN ))
@@ -529,20 +527,15 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,if (count <1 )return -EINVAL ; - max =min (count,sizeof (data) -1 ); -if (copy_from_user (data, buf, max)) -return -EFAULT ; +/* strip trailing '\n' */ +if (buf[count -1 ] =='\n' ) + buf[count -1 ] =0 ; -if (data[max -1 ] =='\n' ) - data[max -1 ] =0 ;/* strip trailing '\n', terminate string */ -else - data[max] =0 ;/* terminate string */ - -if (!strcmp (data,"stop" )) +if (!strcmp (buf,"stop" ))pktgen_stop_all_threads (pn); -else if (!strcmp (data,"start" )) +else if (!strcmp (buf,"start" ))pktgen_run_all_threads (pn); -else if (!strcmp (data,"reset" )) +else if (!strcmp (buf,"reset" ))pktgen_reset_all_threads (pn);else return -EINVAL ;
@@ -552,7 +545,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,static const struct proc_ops pktgen_proc_ops = { .proc_show = pgctrl_show, - .proc_write = pgctrl_write, + .proc_write_buf = pgctrl_write, };static int pktgen_if_show (struct seq_file *seq,void *v)
@@ -741,7 +734,7 @@ static int pktgen_if_show(struct seq_file *seq, void *v) } -static ssize_t hex32_arg (const char __user *user_buffer,size_t maxlen, +static ssize_t hex32_arg (const char *user_buffer,size_t maxlen,__u32 *num) {size_t i =0 ;
@@ -752,8 +745,7 @@ static ssize_t hex32_arg(const char __user *user_buffer, size_t maxlen,int value;char c; -if (get_user (c, &user_buffer[i])) -return -EFAULT ; + c = user_buffer[i]; value =hex_to_bin (c);if (value >=0 ) { *num <<=4 ;
@@ -765,15 +757,14 @@ static ssize_t hex32_arg(const char __user *user_buffer, size_t maxlen,return i; } -static ssize_t count_trail_chars (const char __user *user_buffer,size_t maxlen) +static ssize_t count_trail_chars (const char *user_buffer,size_t maxlen) {size_t i;for (i =0 ; i < maxlen; i++) {char c; -if (get_user (c, &user_buffer[i])) -return -EFAULT ; + c = user_buffer[i];switch (c) {case '\"' :case '\n' :
@@ -790,7 +781,7 @@ done:return i; } -static ssize_t num_arg (const char __user *user_buffer,size_t maxlen, +static ssize_t num_arg (const char *user_buffer,size_t maxlen,unsigned long *num) {size_t i;
@@ -799,8 +790,7 @@ static ssize_t num_arg(const char __user *user_buffer, size_t maxlen,for (i =0 ; i < maxlen; i++) {char c; -if (get_user (c, &user_buffer[i])) -return -EFAULT ; + c = user_buffer[i];if ((c >='0' ) && (c <='9' )) { *num *=10 ; *num += c -'0' ;
@@ -810,15 +800,14 @@ static ssize_t num_arg(const char __user *user_buffer, size_t maxlen,return i; } -static ssize_t strn_len (const char __user *user_buffer,size_t maxlen) +static ssize_t strn_len (const char *user_buffer,size_t maxlen) {size_t i;for (i =0 ; i < maxlen; i++) {char c; -if (get_user (c, &user_buffer[i])) -return -EFAULT ; + c = user_buffer[i];switch (c) {case '\"' :case '\n' :
@@ -840,7 +829,7 @@ done_str:* where each entry consists of size and weight delimited by commas. * "size1,weight_1 size2,weight_2 ... size_n,weight_n" for example. */ -static ssize_t get_imix_entries (const char __user *buffer, +static ssize_t get_imix_entries (const char *buffer,size_t maxlen,struct pktgen_dev *pkt_dev) {
@@ -867,8 +856,7 @@ static ssize_t get_imix_entries(const char __user *buffer, i += len;if (i >= maxlen)return -EINVAL ; -if (get_user (c, &buffer[i])) -return -EFAULT ; + c = buffer[i];/* Check for comma between size_i and weight_i */ if (c !=',' )return -EINVAL ;
@@ -894,15 +882,14 @@ static ssize_t get_imix_entries(const char __user *buffer,if (i >= maxlen)break ; -if (get_user (c, &buffer[i])) -return -EFAULT ; + c = buffer[i]; i++; }while (c ==' ' );return i; } -static ssize_t get_labels (const char __user *buffer, +static ssize_t get_labels (const char *buffer,size_t maxlen,struct pktgen_dev *pkt_dev) {unsigned int n =0 ;
@@ -936,8 +923,7 @@ static ssize_t get_labels(const char __user *buffer, n++;if (i >= maxlen)break ; -if (get_user (c, &buffer[i])) -return -EFAULT ; + c = buffer[i]; i++; }while (c ==',' );
@@ -974,9 +960,8 @@ static __u32 pktgen_read_flag(const char *f, bool *disable)return 0 ; } -static ssize_t pktgen_if_write (struct file *file, -const char __user *user_buffer,size_t count, -loff_t *offset) +static ssize_t pktgen_if_write (struct file *file,char *user_buffer, +size_t count,loff_t *offset) {struct seq_file *seq = file->private_data;struct pktgen_dev *pkt_dev = seq->private;
@@ -1009,8 +994,7 @@ static ssize_t pktgen_if_write(struct file *file,return len;memset (name,0 ,sizeof (name)); -if (copy_from_user (name, &user_buffer[i], len)) -return -EFAULT ; +memcpy (name, &user_buffer[i], len); i += len; max = count - i;
@@ -1020,16 +1004,9 @@ static ssize_t pktgen_if_write(struct file *file, i += len; -if (debug) { -size_t copy =min_t (size_t, count +1 ,1024 ); -char *tp =strndup_user (user_buffer, copy); - -if (IS_ERR (tp)) -return PTR_ERR (tp); - -pr_debug ("%s,%zu buffer -:%s:-\n" , name, count, tp); -kfree (tp); - } +if (debug) +pr_debug ("%s,%zu buffer -:%.*s:-\n" , name, count, + (int )min_t (size_t, count,1023 ), user_buffer);if (!strcmp (name,"min_pkt_size" )) { max =min (10 , count - i);
@@ -1322,8 +1299,7 @@ static ssize_t pktgen_if_write(struct file *file,return len;memset (f,0 ,sizeof (f)); -if (copy_from_user (f, &user_buffer[i], len)) -return -EFAULT ; +memcpy (f, &user_buffer[i], len);if (strcmp (f,"start_xmit" ) ==0 ) { pkt_dev->xmit_mode =M_START_XMIT ;
@@ -1362,8 +1338,7 @@ static ssize_t pktgen_if_write(struct file *file,return len;memset (f,0 ,32 ); -if (copy_from_user (f, &user_buffer[i], len)) -return -EFAULT ; +memcpy (f, &user_buffer[i], len); flag =pktgen_read_flag (f, &disable);if (flag) {
@@ -1410,8 +1385,7 @@ static ssize_t pktgen_if_write(struct file *file,if (len <0 )return len; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;if (strcmp (buf, pkt_dev->dst_min) !=0 ) {strscpy_pad (pkt_dev->dst_min, buf);
@@ -1430,8 +1404,7 @@ static ssize_t pktgen_if_write(struct file *file,if (len <0 )return len; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;if (strcmp (buf, pkt_dev->dst_max) !=0 ) {strscpy_pad (pkt_dev->dst_max, buf);
@@ -1452,8 +1425,7 @@ static ssize_t pktgen_if_write(struct file *file, pkt_dev->flags |=F_IPV6 ; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;in6_pton (buf,-1 , pkt_dev->in6_daddr.s6_addr,-1 ,NULL );
@@ -1475,8 +1447,7 @@ static ssize_t pktgen_if_write(struct file *file, pkt_dev->flags |=F_IPV6 ; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;in6_pton (buf,-1 , pkt_dev->min_in6_daddr.s6_addr,-1 ,NULL );
@@ -1497,8 +1468,7 @@ static ssize_t pktgen_if_write(struct file *file, pkt_dev->flags |=F_IPV6 ; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;in6_pton (buf,-1 , pkt_dev->max_in6_daddr.s6_addr,-1 ,NULL );
@@ -1518,8 +1488,7 @@ static ssize_t pktgen_if_write(struct file *file, pkt_dev->flags |=F_IPV6 ; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;in6_pton (buf,-1 , pkt_dev->in6_saddr.s6_addr,-1 ,NULL );
@@ -1539,8 +1508,7 @@ static ssize_t pktgen_if_write(struct file *file,if (len <0 )return len; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;if (strcmp (buf, pkt_dev->src_min) !=0 ) {strscpy_pad (pkt_dev->src_min, buf);
@@ -1559,8 +1527,7 @@ static ssize_t pktgen_if_write(struct file *file,if (len <0 )return len; -if (copy_from_user (buf, &user_buffer[i], len)) -return -EFAULT ; +memcpy (buf, &user_buffer[i], len); buf[len] =0 ;if (strcmp (buf, pkt_dev->src_max) !=0 ) {strscpy_pad (pkt_dev->src_max, buf);
@@ -1580,8 +1547,7 @@ static ssize_t pktgen_if_write(struct file *file,return len;memset (valstr,0 ,sizeof (valstr)); -if (copy_from_user (valstr, &user_buffer[i], len)) -return -EFAULT ; +memcpy (valstr, &user_buffer[i], len);if (!mac_pton (valstr, pkt_dev->dst_mac))return -EINVAL ;
@@ -1598,8 +1564,7 @@ static ssize_t pktgen_if_write(struct file *file,return len;memset (valstr,0 ,sizeof (valstr)); -if (copy_from_user (valstr, &user_buffer[i], len)) -return -EFAULT ; +memcpy (valstr, &user_buffer[i], len);if (!mac_pton (valstr, pkt_dev->src_mac))return -EINVAL ;
@@ -1864,7 +1829,7 @@ static ssize_t pktgen_if_write(struct file *file,static const struct proc_ops pktgen_if_proc_ops = { .proc_show = pktgen_if_show, - .proc_write = pktgen_if_write, + .proc_write_buf = pktgen_if_write, };static int pktgen_thread_show (struct seq_file *seq,void *v)
@@ -1897,8 +1862,7 @@ static int pktgen_thread_show(struct seq_file *seq, void *v)return 0 ; } -static ssize_t pktgen_thread_write (struct file *file, -const char __user *user_buffer, +static ssize_t pktgen_thread_write (struct file *file,char *user_buffer,size_t count,loff_t *offset) {struct seq_file *seq = file->private_data;
@@ -1927,8 +1891,7 @@ static ssize_t pktgen_thread_write(struct file *file,return len;memset (name,0 ,sizeof (name)); -if (copy_from_user (name, &user_buffer[i], len)) -return -EFAULT ; +memcpy (name, &user_buffer[i], len); i += len; max = count - i;
@@ -1959,8 +1922,7 @@ static ssize_t pktgen_thread_write(struct file *file, ret = len; goto out; } -if (copy_from_user (f, &user_buffer[i], len)) -return -EFAULT ; +memcpy (f, &user_buffer[i], len);mutex_lock (&pktgen_thread_lock); ret =pktgen_add_device (t, f);
@@ -1996,7 +1958,7 @@ out:static const struct proc_ops pktgen_thread_proc_ops = { .proc_show = pktgen_thread_show, - .proc_write = pktgen_thread_write, + .proc_write_buf = pktgen_thread_write, };/* Think find or remove for NN */
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 4/13 netfilter: xt_recent: let procfs own the seq_file
In reply to Christian BraunerDeclare the seq_operations and the size of the iterator state and let procfs open and free the seq_file. ->proc_open() only fills in the table now. Reading /proc/net/xt_recent/<table> then no longer holds up the removal of the table.
--- net/netfilter/xt_recent.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
net/netfilter/xt_recent.c +3 -8
@@ -546,11 +546,7 @@ static const struct seq_operations recent_seq_ops = {static int recent_seq_open (struct inode *inode,struct file *file) { -struct recent_iter_state *st; - - st =__seq_open_private (file, &recent_seq_ops,sizeof (*st)); -if (st ==NULL ) -return -ENOMEM ; +struct recent_iter_state *st = ((struct seq_file *)file->private_data)->private; st->table =pde_data (inode);return 0 ;
@@ -626,11 +622,10 @@ recent_mt_proc_write(struct file *file, const char __user *input, }static const struct proc_ops recent_mt_proc_ops = { + .proc_seq_ops = &recent_seq_ops, + .proc_state_size =sizeof (struct recent_iter_state ), .proc_open = recent_seq_open, - .proc_read = seq_read, .proc_write = recent_mt_proc_write, - .proc_release = seq_release_private, - .proc_lseek = seq_lseek, };static int __net_init recent_proc_net_init (struct net *net)
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 5/13 netfilter: xt_recent: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written to /proc/net/xt_recent/<table> before it pins the entry, and take the address from that copy. The removal of a table runs under recent_mutex and doesn't wait for a writer that faults on its buffer anymore. Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now.
--- net/netfilter/xt_recent.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/netfilter/xt_recent.c +3 -5
@@ -553,8 +553,7 @@ static int recent_seq_open(struct inode *inode, struct file *file) }static ssize_t -recent_mt_proc_write (struct file *file,const char __user *input, -size_t size,loff_t *loff) +recent_mt_proc_write (struct file *file,char *input,size_t size,loff_t *loff) {struct recent_table *t =pde_data (file_inode (file));struct recent_entry *e;
@@ -568,8 +567,7 @@ recent_mt_proc_write(struct file *file, const char __user *input,return 0 ;if (size >sizeof (buf)) size =sizeof (buf); -if (copy_from_user (buf, input, size) !=0 ) -return -EFAULT ; +memcpy (buf, input, size);/* Strict protocol! */ if (*loff !=0 )
@@ -625,7 +623,7 @@ static const struct proc_ops recent_mt_proc_ops = { .proc_seq_ops = &recent_seq_ops, .proc_state_size = sizeof(struct recent_iter_state), .proc_open = recent_seq_open, - .proc_write = recent_mt_proc_write, + .proc_write_buf = recent_mt_proc_write, };static int __net_init recent_proc_net_init (struct net *net)
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 6/13 SUNRPC: let procfs own the seq_file of the cache content file
In reply to Christian BraunerDeclare the seq_operations and let procfs open and free the seq_file of /proc/net/rpc/<cache>/content. ->proc_open() and ->proc_release() only take and drop the module reference and set up ->private now. The rpc_pipefs file is unchanged. Reading the procfs file then no longer holds up its removal when the network namespace goes away.
--- net/sunrpc/cache.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/sunrpc/cache.c +8 -4
@@ -1606,24 +1606,28 @@ static const struct proc_ops cache_channel_proc_ops = { .proc_release = cache_release_procfs, }; +/* procfs opens the seq_file */ static int content_open_procfs (struct inode *inode,struct file *filp) {struct cache_detail *cd =pde_data (inode); -return content_open (inode, filp, cd); +if (!cd || !try_module_get (cd->owner)) +return -EACCES ; + ((struct seq_file *)filp->private_data)->private = cd; +return 0 ; }static int content_release_procfs (struct inode *inode,struct file *filp) {struct cache_detail *cd =pde_data (inode); -return content_release (inode, filp, cd); +module_put (cd->owner); +return 0 ; }static const struct proc_ops content_proc_ops = { + .proc_seq_ops = &cache_content_op, .proc_open = content_open_procfs, - .proc_read = seq_read, - .proc_lseek = seq_lseek, .proc_release = content_release_procfs, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 7/13 SUNRPC: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() for the procfs channel, flush and use-gss-proxy files so procfs copies in what is written before it pins the entry. The channel file parses the downcall from that copy and the flush files share the parsing with rpc_pipefs in do_write_flush(). The rpc_pipefs files keep copying in themselves.
CACHE_DOWNCALL_MAX and CACHE_FLUSH_MAX name the limits both sides enforce, procfs through ->proc_write_size. The procfs files are removed when the network namespace goes away and that no longer waits for a writer that faults on its buffer.
--- net/sunrpc/auth_gss/svcauth_gss.c | 10 +++---- net/sunrpc/cache.c | 63 +++++++++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 25 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +4 -6
@@ -1408,8 +1408,8 @@ svcauth_gss_proc_init(struct svc_rqst *rqstp, struct rpc_gss_wire_cred *gc)#ifdef CONFIG_PROC_FS -static ssize_t write_gssp (struct file *file,const char __user *buf, -size_t count,loff_t *ppos) +static ssize_t write_gssp (struct file *file,char *buf,size_t count, +loff_t *ppos) {struct net *net =pde_data (file_inode (file));char tbuf[20 ];
@@ -1418,9 +1418,7 @@ static ssize_t write_gssp(struct file *file, const char __user *buf,if (*ppos || count >sizeof (tbuf)-1 )return -EINVAL ; -if (copy_from_user (tbuf, buf, count)) -return -EFAULT ; - +memcpy (tbuf, buf, count); tbuf[count] =0 ; res =kstrtoul (tbuf,0 , &i);if (res)
@@ -1468,7 +1466,7 @@ static ssize_t read_gssp(struct file *file, char __user *buf,static const struct proc_ops use_gss_proxy_proc_ops = { .proc_open = nonseekable_open, - .proc_write = write_gssp, + .proc_write_buf = write_gssp, .proc_read = read_gssp, };
net/sunrpc/cache.c +44 -19
120 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH RESEND v2 07/13] SUNRPC: let procfs copy in writes
Quoted 6 lines · Christian Brauner
Implement ->proc_write_buf() for the procfs channel, flush and use-gss-proxy files so procfs copies in what is written before it pins the entry. The channel file parses the downcall from that copy and the flush files share the parsing with
rpc_pipefsindo_write_flush(). Therpc_pipefsfiles keep copying in themselves.
Quoted 6 lines
CACHE_DOWNCALL_MAXandCACHE_FLUSH_MAXname the limits both sides enforce, procfs through ->proc_write_size. The procfs files are removed when the network namespace goes away and that no longer waits for a writer that faults on its buffer.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Christian Brauner
maintainerPATCH RESEND v2 8/13 SUNRPC: let procfs copy out reads
In reply to Christian BraunerImplement ->proc_read_buf() for the procfs channel, flush, use-gss-proxy and gss_krb5_enctypes files so procfs copies what is read to userspace after it unpinned the entry.
cache_read() takes an iov_iter now. The rpc_pipefs channel file passes one for the user buffer and behaves like before. The procfs one passes one for procfs' buffer, and a read still hands out at most one request. A reader of the procfs channel file whose copy out fails, a readv() with a bad later segment included, loses what was handed out, since the request moves on before procfs copies it out. If that was only part of a request the next read returns the rest of it. Both flush files share flush_time_text().
The procfs files are removed when the network namespace goes away and that no longer waits for a reader that faults on its buffer.
--- net/sunrpc/auth_gss/svcauth_gss.c | 24 ++++++------------- net/sunrpc/cache.c | 50 +++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 38 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +7 -17
@@ -1442,32 +1442,22 @@ static ssize_t write_gssp(struct file *file, char *buf, size_t count,return count; } -static ssize_t read_gssp (struct file *file,char __user *buf, +static ssize_t read_gssp (struct file *file,char *buf,size_t count,loff_t *ppos) {struct net *net =pde_data (file_inode (file));struct sunrpc_net *sn =net_generic (net, sunrpc_net_id); -unsigned long p = *ppos;char tbuf[10 ];size_t len; -snprintf (tbuf,sizeof (tbuf),"%d\n" , sn->use_gss_proxy); - len =strlen (tbuf); -if (p >= len) -return 0 ; - len -= p; -if (len > count) - len = count; -if (copy_to_user (buf, (void *)(tbuf+p), len)) -return -EFAULT ; - *ppos += len; -return len; + len =snprintf (tbuf,sizeof (tbuf),"%d\n" , sn->use_gss_proxy); +return memory_read_from_buffer (buf, count, ppos, tbuf, len); }static const struct proc_ops use_gss_proxy_proc_ops = { .proc_open = nonseekable_open, .proc_write_buf = write_gssp, - .proc_read = read_gssp, + .proc_read_buf = read_gssp, };static int create_use_gss_proxy_proc_entry (struct net *net)
@@ -1494,7 +1484,7 @@ static void destroy_use_gss_proxy_proc_entry(struct net *net) } } -static ssize_t read_gss_krb5_enctypes (struct file *file,char __user *buf, +static ssize_t read_gss_krb5_enctypes (struct file *file,char *buf,size_t count,loff_t *ppos) {struct rpcsec_gss_oid oid = {
@@ -1512,7 +1502,7 @@ static ssize_t read_gss_krb5_enctypes(struct file *file, char __user *buf,return 0 ; } - ret =simple_read_from_buffer (buf, count, ppos, + ret =memory_read_from_buffer (buf, count, ppos, mech->gm_upcall_enctypes,strlen (mech->gm_upcall_enctypes));gss_mech_put (mech);
@@ -1521,7 +1511,7 @@ static ssize_t read_gss_krb5_enctypes(struct file *file, char __user *buf,static const struct proc_ops gss_krb5_enctypes_proc_ops = { .proc_open = nonseekable_open, - .proc_read = read_gss_krb5_enctypes, + .proc_read_buf = read_gss_krb5_enctypes, };static int create_krb5_enctypes_proc_entry (struct net *net)
net/sunrpc/cache.c +29 -21
121 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH RESEND v2 08/13] SUNRPC: let procfs copy out reads
Quoted 13 lines · Christian Brauner
Implement ->proc_read_buf() for the procfs channel, flush, use-gss-proxy and
gss_krb5_enctypesfiles so procfs copies what is read to userspace after it unpinned the entry.
cache_read()takes aniov_iternow. Therpc_pipefschannel file passes one for the user buffer and behaves like before. The procfs one passes one for procfs' buffer, and a read still hands out at most one request. A reader of the procfs channel file whose copy out fails, areadv()with a bad later segment included, loses what was handed out, since the request moves on before procfs copies it out. If that was only part of a request the next read returns the rest of it. Both flush files shareflush_time_text().
Quoted 4 lines
The procfs files are removed when the network namespace goes away and that no longer waits for a reader that faults on its buffer.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Christian Brauner
maintainerPATCH RESEND v2 9/13 SUNRPC: drop the ioctl of the procfs channel files
In reply to Christian Braunerdo_vfs_ioctl() answers FIONREAD for regular files with i_size - f_pos before it gets to the file's ->unlocked_ioctl(). The channel files are regular files, so cache_ioctl_procfs() has never seen FIONREAD and only ever failed other commands with -EINVAL. Drop it. Other commands fail with -ENOTTY now.
The rpc_pipefs channel files are regular files as well.
--- net/sunrpc/cache.c | 10 ---------- 1 file changed, 10 deletions(-)
net/sunrpc/cache.c +0 -10
@@ -1596,15 +1596,6 @@ static __poll_t cache_poll_procfs(struct file *filp, poll_table *wait)return cache_poll (filp, wait, cd); } -static long cache_ioctl_procfs (struct file *filp, -unsigned int cmd,unsigned long arg) -{ -struct inode *inode =file_inode (filp); -struct cache_detail *cd =pde_data (inode); - -return cache_ioctl (inode, filp, cmd, arg, cd); -} -static int cache_open_procfs (struct inode *inode,struct file *filp) {struct cache_detail *cd =pde_data (inode);
@@ -1624,7 +1615,6 @@ static const struct proc_ops cache_channel_proc_ops = { .proc_write_buf = cache_write_procfs, .proc_write_size = CACHE_DOWNCALL_MAX, .proc_poll = cache_poll_procfs, - .proc_ioctl = cache_ioctl_procfs, /* for FIONREAD */ .proc_open = cache_open_procfs, .proc_release = cache_release_procfs, };
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 10/13 SUNRPC: let procfs own the wait queue of the procfs channel files
In reply to Christian Braunercache_poll() sleeps the poller on queue_wait, which went back to being a static queue so that a poll() on a procfs channel file can't be left on the queue of a cache_detail that its network namespace freed. procfs owns the queue poll() uses now and it outlives the file, so the procfs channel files leave the poll_wait() to procfs and an upcall wakes their pollers through proc_poll_notify(). The channel entry is remembered in the cache_detail for that and forgotten before the entries are removed. The rpc_pipefs files keep sleeping on queue_wait, procfs has nothing to do with them.
--- include/linux/sunrpc/cache.h | 2 ++ net/sunrpc/cache.c | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-)
include/linux/sunrpc/cache.h +2 -0
@@ -129,6 +129,8 @@ struct cache_detail {struct proc_dir_entry *procfs;struct dentry *pipefs; }; +/* the channel file in @procfs, for proc_poll_notify() */ +struct proc_dir_entry *procfs_channel;struct net *net; };
net/sunrpc/cache.c +11 -9
@@ -970,20 +970,18 @@ out: }/* -* Not in struct cache_detail: poll and epoll waiters stay queued until -* their file is closed, but a channel file in procfs can stay open after -* the cache_detail of its dying network namespace has been freed. +* For the rpc_pipefs channel files. Not in struct cache_detail: poll and +* epoll waiters stay queued until their file is closed, which can be after +* the cache_detail is gone. The procfs channel files are polled on the wait +* queue procfs owns for them instead, see proc_poll_notify(). */ static DECLARE_WAIT_QUEUE_HEAD (queue_wait); -static __poll_t cache_poll (struct file *filp,poll_table *wait, -struct cache_detail *cd) +static __poll_t cache_poll (struct file *filp,struct cache_detail *cd) {__poll_t mask;struct cache_reader *rp = filp->private_data; -poll_wait (filp, &queue_wait, wait); -/* alway allow write */ mask =EPOLLOUT |EPOLLWRNORM ;
@@ -1248,6 +1246,7 @@ static int cache_do_upcall(struct cache_detail *detail, struct cache_head *h)if (ret != -EAGAIN && detail->cache_notify) detail->cache_notify (detail, h);wake_up (&queue_wait); +proc_poll_notify (detail->procfs_channel);if (ret == -EAGAIN ) {kfree (buf);kfree (crq);
@@ -1593,7 +1592,7 @@ static __poll_t cache_poll_procfs(struct file *filp, poll_table *wait) {struct cache_detail *cd =pde_data (file_inode (filp)); -return cache_poll (filp, wait, cd); +return cache_poll (filp, cd); }static int cache_open_procfs (struct inode *inode,struct file *filp)
@@ -1690,6 +1689,7 @@ static const struct proc_ops cache_flush_proc_ops = {static void remove_cache_proc_entries (struct cache_detail *cd) {if (cd->procfs) { + cd->procfs_channel =NULL ;proc_remove (cd->procfs); cd->procfs =NULL ; }
@@ -1718,6 +1718,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net) &cache_channel_proc_ops, cd);if (p ==NULL ) goto out_nomem; + cd->procfs_channel = p; }if (cd->cache_show) { p = proc_create_data("content", S_IFREG | 0400, cd->procfs,
@@ -1806,7 +1807,8 @@ static __poll_t cache_poll_pipefs(struct file *filp, poll_table *wait) {struct cache_detail *cd =RPC_I (file_inode (filp))->private; -return cache_poll (filp, wait, cd); +poll_wait (filp, &queue_wait, wait); +return cache_poll (filp, cd); } static long cache_ioctl_pipefs(struct file *filp,
Signature · 1 line
2.53.0
Re: [PATCH RESEND v2 10/13] SUNRPC: let procfs own the wait queue of the procfs channel files
Quoted 10 lines · Christian Brauner
cache_poll()sleeps the poller onqueue_wait, which went back to being a static queue so that apoll()on a procfs channel file can't be left on the queue of acache_detailthat its network namespace freed. procfs owns the queuepoll()uses now and it outlives the file, so the procfs channel files leave thepoll_wait()to procfs and an upcall wakes their pollers throughproc_poll_notify(). The channel entry is remembered in thecache_detailfor that and forgotten before the entries are removed. Therpc_pipefsfiles keep sleeping onqueue_wait, procfs has nothing to do with them.
Quoted 2 lines
Signed-off-by Christian Brauner (Amutable) <[email protected]>---
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Christian Brauner
maintainerPATCH RESEND v2 11/13 samples/kfifo: let procfs copy in writes
In reply to Christian BraunerImplement ->proc_write_buf() so procfs copies in what is written before it pins the entry, and put that copy into the fifo with kfifo_in() instead of kfifo_from_user(). Writes larger than PAGE_SIZE - 1 bytes fail with -EINVAL now. kfifo_from_user() cut a record to 255 bytes, what the one byte that holds its length can say, so the record sample keeps doing that with PROC_ENTRY_SHORT_WRITES.
--- samples/kfifo/bytestream-example.c | 9 +++------ samples/kfifo/inttype-example.c | 10 ++++------ samples/kfifo/record-example.c | 12 ++++++------ 3 files changed, 13 insertions(+), 18 deletions(-)
samples/kfifo/bytestream-example.c +3 -6
@@ -110,20 +110,17 @@ static int __init testfunc(void)return 0 ; } -static ssize_t fifo_write (struct file *file,const char __user *buf, +static ssize_t fifo_write (struct file *file,char *buf,size_t count,loff_t *ppos) { -int ret;unsigned int copied;if (mutex_lock_interruptible (&write_access))return -ERESTARTSYS ; - ret =kfifo_from_user (&test, buf, count, &copied); + copied =kfifo_in (&test, buf, count);mutex_unlock (&write_access); -if (ret) -return ret;return copied; }
@@ -148,7 +145,7 @@ static ssize_t fifo_read(struct file *file, char __user *buf,static const struct proc_ops fifo_proc_ops = { .proc_read = fifo_read, - .proc_write = fifo_write, + .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, };
samples/kfifo/inttype-example.c +4 -6
@@ -103,20 +103,18 @@ static int __init testfunc(void)return 0 ; } -static ssize_t fifo_write (struct file *file,const char __user *buf, +static ssize_t fifo_write (struct file *file,char *buf,size_t count,loff_t *ppos) { -int ret;unsigned int copied;if (mutex_lock_interruptible (&write_access))return -ERESTARTSYS ; - ret =kfifo_from_user (&test, buf, count, &copied); + copied =kfifo_in (&test, (const int *)buf, count /sizeof (int )) * +sizeof (int );mutex_unlock (&write_access); -if (ret) -return ret;return copied; }
@@ -141,7 +139,7 @@ static ssize_t fifo_read(struct file *file, char __user *buf,static const struct proc_ops fifo_proc_ops = { .proc_read = fifo_read, - .proc_write = fifo_write, + .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, };
samples/kfifo/record-example.c +6 -6
@@ -117,20 +117,17 @@ static int __init testfunc(void)return 0 ; } -static ssize_t fifo_write (struct file *file,const char __user *buf, +static ssize_t fifo_write (struct file *file,char *buf,size_t count,loff_t *ppos) { -int ret;unsigned int copied;if (mutex_lock_interruptible (&write_access))return -ERESTARTSYS ; - ret =kfifo_from_user (&test, buf, count, &copied); + copied =kfifo_in (&test, buf, count);mutex_unlock (&write_access); -if (ret) -return ret;return copied; }
@@ -155,8 +152,11 @@ static ssize_t fifo_read(struct file *file, char __user *buf,static const struct proc_ops fifo_proc_ops = { .proc_read = fifo_read, - .proc_write = fifo_write, + .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, +/* kfifo_from_user() cut a record to what its length byte holds */ + .proc_flags =PROC_ENTRY_SHORT_WRITES , + .proc_write_size =U8_MAX , };static int __init example_init (void )
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 12/13 samples/kfifo: let procfs copy out reads
In reply to Christian BraunerImplement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry, and take the data out of the fifo with kfifo_out() instead of kfifo_to_user(). A reader that passes a bad buffer loses what was taken out for it now, kfifo_to_user() left that in the fifo. The samples can be spliced now too, and a sendfile() from them into a target that fails or takes less than was read drops what was taken out in between, like for the rtas error log.
--- samples/kfifo/bytestream-example.c | 9 +++------ samples/kfifo/inttype-example.c | 10 ++++------ samples/kfifo/record-example.c | 9 +++------ 3 files changed, 10 insertions(+), 18 deletions(-)
samples/kfifo/bytestream-example.c +3 -6
@@ -125,26 +125,23 @@ static ssize_t fifo_write(struct file *file, char *buf,return copied; } -static ssize_t fifo_read (struct file *file,char __user *buf, +static ssize_t fifo_read (struct file *file,char *buf,size_t count,loff_t *ppos) { -int ret;unsigned int copied;if (mutex_lock_interruptible (&read_access))return -ERESTARTSYS ; - ret =kfifo_to_user (&test, buf, count, &copied); + copied =kfifo_out (&test, buf, count);mutex_unlock (&read_access); -if (ret) -return ret;return copied; }static const struct proc_ops fifo_proc_ops = { - .proc_read = fifo_read, + .proc_read_buf = fifo_read, .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, };
samples/kfifo/inttype-example.c +4 -6
@@ -119,26 +119,24 @@ static ssize_t fifo_write(struct file *file, char *buf,return copied; } -static ssize_t fifo_read (struct file *file,char __user *buf, +static ssize_t fifo_read (struct file *file,char *buf,size_t count,loff_t *ppos) { -int ret;unsigned int copied;if (mutex_lock_interruptible (&read_access))return -ERESTARTSYS ; - ret =kfifo_to_user (&test, buf, count, &copied); + copied =kfifo_out (&test, (int *)buf, count /sizeof (int )) * +sizeof (int );mutex_unlock (&read_access); -if (ret) -return ret;return copied; }static const struct proc_ops fifo_proc_ops = { - .proc_read = fifo_read, + .proc_read_buf = fifo_read, .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, };
samples/kfifo/record-example.c +3 -6
@@ -132,26 +132,23 @@ static ssize_t fifo_write(struct file *file, char *buf,return copied; } -static ssize_t fifo_read (struct file *file,char __user *buf, +static ssize_t fifo_read (struct file *file,char *buf,size_t count,loff_t *ppos) { -int ret;unsigned int copied;if (mutex_lock_interruptible (&read_access))return -ERESTARTSYS ; - ret =kfifo_to_user (&test, buf, count, &copied); + copied =kfifo_out (&test, buf, count);mutex_unlock (&read_access); -if (ret) -return ret;return copied; }static const struct proc_ops fifo_proc_ops = { - .proc_read = fifo_read, + .proc_read_buf = fifo_read, .proc_write_buf = fifo_write, .proc_lseek = noop_llseek,/* kfifo_from_user() cut a record to what its length byte holds */
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 13/13 selftests/proc: check that removing a polled entry wakes its pollers
In reply to Christian BraunerPoll the channel file of a sunrpc cache in /proc/net of a network namespace of its own and let the namespace die while the poller sleeps:
- the poller wakes up and gets POLLERR | POLLPRI
- so does an epoll with an item on the entry
- a poll of the removed entry keeps reporting POLLERR, and a read of it fails with -EIO
The namespace is torn down from a workqueue, so a regression stalls the test for ten seconds before it fails.
--- tools/testing/selftests/proc/.gitignore | 1 + tools/testing/selftests/proc/Makefile | 1 + tools/testing/selftests/proc/config | 2 + tools/testing/selftests/proc/proc-remove-polled.c | 189 ++++++++++++++++++++++ 4 files changed, 193 insertions(+)
tools/testing/selftests/proc/.gitignore +1 -0
@@ -31,5 +31,6 @@ /self /setns-dcache /setns-sysvipc +/proc-remove-polled /proc-sysctl-readdir-churn /thread-self
tools/testing/selftests/proc/Makefile +1 -0
@@ -30,6 +30,7 @@ TEST_GEN_PROGS += setns-sysvipc TEST_GEN_PROGS += thread-self TEST_GEN_PROGS += proc-multiple-procfs TEST_GEN_PROGS += proc-fsconfig-hidepid +TEST_GEN_PROGS += proc-remove-polled TEST_GEN_PROGS += proc-sysctl-readdir-churn TEST_GEN_PROGS += proc-pidns TEST_GEN_PROGS += proc-remove-slow-sysctl
tools/testing/selftests/proc/config +2 -0
@@ -6,6 +6,8 @@ CONFIG_NET_NS=y CONFIG_IPV6=y CONFIG_TUN=y CONFIG_USERFAULTFD=y +CONFIG_USER_NS=y +CONFIG_SUNRPC=y CONFIG_SOUND=y CONFIG_SND=y CONFIG_SND_DUMMY=m
tools/testing/selftests/proc/proc-remove-polled.c new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.53.0
Christian Brauner
maintainerv2 cover proc: drop the __user methods (Part 7/7)
In reply to Christian BraunerPart 7/7 of "proc: move procfs to what kernfs does", on top of parts 3 to 6:
https://patch.msgid.link/20261104-work-procfs-v2-0-b45cd5789ac5@brauner
This is the final part of letting procfs own the data path.Every entry that can be removed reads, writes and handles ioctls through procfs' buffers now, so its code only runs with the entry pinned and never touches userspace memory.
Drop ->proc_write(), ->proc_ioctl() and ->proc_compat_ioctl(). The entries that keep reading straight into userspace, kcore, kmsg and the kpage files, are built in and never removed, so procfs never pins them and nothing can wait for them. They get a file_operations of their own that goes into the inode as it is.
Afterwards, nothing in struct proc_ops takes a __user pointer anymore, and one set of file_operations serves every entry that has proc_ops, like kernfs_file_fops does. For those five files mmap() fails with -ENODEV instead of -EIO now and a write() by someone who can open them for writing with -EINVAL instead of -EIO. Nothing else changes for them.
With the old names free the _buf suffix of the new methods doesn't mean anything anymore, so ->proc_write_buf(), ->proc_read_buf() and ->proc_ioctl_buf() become ->proc_write(), ->proc_read() and ->proc_ioctl() at the end.
The last patch takes the poll_table away from ->proc_poll(), so that an entry can't hand procfs a queue that dies before its files do.
With the whole stack on a KASAN and lockdep kernel the removal selftests of all parts pass, the proc, pktgen and allocinfo selftests behave like without it, and kcore, kmsg, the kpage files and /proc/profile behave the same syscall by syscall, read, pread, seek, splice, poll and ioctl included, apart from the two errno changes above and splice() now working on /proc/profile.
---
Changes in v2:
- kcore, kmsg and the kpage files get file_operations of their own
instead of staying the permanent exception, and ->proc_read() and ->proc_read_iter() go away with them: nothing in struct proc_ops takes
a __user pointer anymore; a splice() from a write-only entry fails
with -EIO instead of -EINVAL now that one set of file_operations
serves every entry
- the poll_table is dropped from ->proc_poll()
- rebased onto v7.4-rc1
- Link to v1: https://patch.msgid.link/[email protected]
---
Christian Brauner (6):
proc: drop ->proc_write()
proc: drop ->proc_ioctl() and ->proc_compat_ioctl()
proc: give kcore, kmsg and the kpage files their own file_operations
proc: drop ->proc_read() and ->proc_read_iter()
proc: drop the _buf suffix from the new methods
proc: drop the poll_table from ->proc_poll()arch/alpha/kernel/srm_env.c | 2 +- arch/arm/kernel/atags_proc.c | 2 +- arch/arm/mm/alignment.c | 2 +- arch/m68k/kernel/bootinfo_proc.c | 2 +- arch/powerpc/kernel/proc_powerpc.c | 2 +- arch/powerpc/kernel/rtas-proc.c | 10 +- arch/powerpc/kernel/rtas_flash.c | 16 +-- arch/powerpc/kernel/rtasd.c | 4 +- arch/powerpc/platforms/pseries/lpar.c | 4 +- arch/powerpc/platforms/pseries/lparcfg.c | 2 +- arch/powerpc/platforms/pseries/reconfig.c | 2 +- arch/sh/mm/alignment.c | 2 +- arch/sparc/kernel/led.c | 2 +- arch/um/drivers/mconsole_kern.c | 2 +- arch/um/kernel/exitcode.c | 2 +- arch/x86/kernel/cpu/mtrr/if.c | 4 +- arch/xtensa/platforms/iss/simdisk.c | 4 +- drivers/acpi/proc.c | 2 +- drivers/hwmon/dell-smm-hwmon.c | 2 +- drivers/input/input.c | 2 +- drivers/macintosh/via-pmu.c | 2 +- drivers/md/md.c | 2 +- drivers/net/wireless/intel/ipw2x00/libipw_module.c | 2 +- drivers/pci/proc.c | 6 +- drivers/platform/x86/lenovo/thinkpad_acpi.c | 2 +- drivers/platform/x86/toshiba_acpi.c | 8 +- drivers/pnp/isapnp/proc.c | 2 +- drivers/pnp/pnpbios/proc.c | 2 +- drivers/s390/block/dasd_proc.c | 2 +- drivers/s390/cio/blacklist.c | 2 +- drivers/s390/cio/css.c | 2 +- drivers/scsi/esas2r/esas2r_main.c | 2 +- drivers/scsi/scsi_devinfo.c | 2 +- drivers/scsi/scsi_proc.c | 4 +- drivers/scsi/sg.c | 4 +- drivers/tty/sysrq.c | 2 +- drivers/usb/gadget/function/rndis.c | 2 +- drivers/video/fbdev/via/viafbdev.c | 14 +- drivers/zorro/proc.c | 2 +- fs/jfs/jfs_debug.c | 2 +- fs/lockd/procfs.c | 4 +- fs/ntfs3/super.c | 2 +- fs/proc/generic.c | 60 +++++---- fs/proc/inode.c | 146 ++++----------------- fs/proc/internal.h | 21 +-- fs/proc/kcore.c | 14 +- fs/proc/kmsg.c | 17 +-- fs/proc/page.c | 27 ++-- fs/proc/proc_net.c | 4 +- fs/proc/vmcore.c | 2 +- fs/smb/client/cifs_debug.c | 16 +-- fs/smb/client/dfs_cache.c | 2 +- include/linux/proc_fs.h | 39 +++--- kernel/configs.c | 2 +- kernel/irq/proc.c | 6 +- kernel/latencytop.c | 2 +- kernel/locking/lockdep_proc.c | 2 +- kernel/profile.c | 4 +- kernel/sched/psi.c | 12 +- lib/dynamic_debug.c | 2 +- mm/alloc_tag.c | 2 +- mm/swapfile.c | 2 +- net/atm/proc.c | 2 +- net/core/pktgen.c | 6 +- net/netfilter/xt_recent.c | 2 +- net/sunrpc/auth_gss/svcauth_gss.c | 6 +- net/sunrpc/cache.c | 10 +- samples/kfifo/bytestream-example.c | 4 +- samples/kfifo/inttype-example.c | 4 +- samples/kfifo/record-example.c | 4 +- sound/core/info.c | 8 +- 71 files changed, 242 insertions(+), 328 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261030-work-procfs-cleanup-1694f71bb156
prerequisite-change-id: 20261101-work-procfs-arch-8d4ade48be31:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
prerequisite-patch-id: 504e13cb7af5da6f3c8503f9336116ddd6ee9fc0
prerequisite-patch-id: 079f5420c7c6660679b25a93ab2912b42af19d6d
prerequisite-patch-id: 717bfde0d4141e875562d62b0e3c22d687517462
prerequisite-patch-id: 3e465d93cacbb875c5508b106bcaae53665de29e
prerequisite-patch-id: daa2e27b0b2dbf5ac04776bf03b0953d9f10bcbb
prerequisite-patch-id: a293472d78b43026dacbfe22a34ba1f8f2626e63
prerequisite-patch-id: f0a09eebade394217c88730e272d7bd33616f982
prerequisite-patch-id: 8471e839ad125d2f4cd9072486ae7da137619c1b
prerequisite-patch-id: 16433e5bde53510f9e6b7e04db2279bd0a8f63f5
prerequisite-patch-id: 03d349761a5a56d223067b051b1a38d594006ae2
prerequisite-patch-id: ffc6f41124e66357a7872aa1553e5404a7d48a55
prerequisite-patch-id: 901a0c1b4c2da010722471826fbfc51402ab8573
prerequisite-patch-id: 1204b4883154dea8cb7d93efadb9f49e70ecd7a8
prerequisite-patch-id: d2762d5dd1254bf7cf89a16b317b7b421718935f
prerequisite-patch-id: d1337f7a08fd4758a94bc5b2faeb30cbad1fe9cf
prerequisite-patch-id: a1d46785e75f0ec87cd12807cb57adc869a7f6a8
prerequisite-patch-id: 44c5d2365c5237b44a0162be9e73dcb392deab2c
prerequisite-patch-id: ad7ca39e7946dbf9e9ed4677b577bb5efad15af5
prerequisite-patch-id: 3984bbb1dbd74d87215a789483a75e968e81b453
prerequisite-patch-id: 48c81c042a9252249b32613e94f6bbca2fcb64b5
prerequisite-patch-id: 4d97d31af7bca868bf68a61fe7825dcbd7cc500b
prerequisite-patch-id: 227908b78f668bc6301cfa2217fa581471176b0f
prerequisite-patch-id: b4cbc3d04d64c061cc9cf2d22412ab5b4b37baaa
prerequisite-change-id: 20261101-work-procfs-drivers-58cd83649658:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
prerequisite-patch-id: 504e13cb7af5da6f3c8503f9336116ddd6ee9fc0
prerequisite-patch-id: 079f5420c7c6660679b25a93ab2912b42af19d6d
prerequisite-patch-id: 717bfde0d4141e875562d62b0e3c22d687517462
prerequisite-patch-id: 3e465d93cacbb875c5508b106bcaae53665de29e
prerequisite-patch-id: daa2e27b0b2dbf5ac04776bf03b0953d9f10bcbb
prerequisite-patch-id: a293472d78b43026dacbfe22a34ba1f8f2626e63
prerequisite-patch-id: f0a09eebade394217c88730e272d7bd33616f982
prerequisite-patch-id: 8471e839ad125d2f4cd9072486ae7da137619c1b
prerequisite-patch-id: 16433e5bde53510f9e6b7e04db2279bd0a8f63f5
prerequisite-patch-id: 03d349761a5a56d223067b051b1a38d594006ae2
prerequisite-patch-id: ffc6f41124e66357a7872aa1553e5404a7d48a55
prerequisite-patch-id: 901a0c1b4c2da010722471826fbfc51402ab8573
prerequisite-patch-id: 1204b4883154dea8cb7d93efadb9f49e70ecd7a8
prerequisite-patch-id: d2762d5dd1254bf7cf89a16b317b7b421718935f
prerequisite-patch-id: d1337f7a08fd4758a94bc5b2faeb30cbad1fe9cf
prerequisite-patch-id: a1d46785e75f0ec87cd12807cb57adc869a7f6a8
prerequisite-patch-id: 44c5d2365c5237b44a0162be9e73dcb392deab2c
prerequisite-patch-id: ad7ca39e7946dbf9e9ed4677b577bb5efad15af5
prerequisite-patch-id: 3984bbb1dbd74d87215a789483a75e968e81b453
prerequisite-patch-id: 48c81c042a9252249b32613e94f6bbca2fcb64b5
prerequisite-patch-id: 4d97d31af7bca868bf68a61fe7825dcbd7cc500b
prerequisite-patch-id: 227908b78f668bc6301cfa2217fa581471176b0f
prerequisite-patch-id: b4cbc3d04d64c061cc9cf2d22412ab5b4b37baaa
prerequisite-patch-id: fd779ec9acd1cd56b7eb9176cd0a10a548133f0c
prerequisite-patch-id: 5c61093340a745890222477d54f21e1121643c95
prerequisite-patch-id: 1199e9ee338002117fbe257118ff264e64eec0bb
prerequisite-patch-id: 08be0388a5aafb66919d0d678380c33f092738ce
prerequisite-patch-id: f98799e2973376543e67ae7a93ab62a20aa29564
prerequisite-patch-id: f670bed1eba8e1440bbfed164fb0c367f248e231
prerequisite-patch-id: f87d26787b356816be42fe8452d0262857d347b9
prerequisite-patch-id: 88a5543ceb70d27bd05b718480334d0a28133697
prerequisite-patch-id: 544f65704decf1a67848c8dc68ac60c5b76cdb81
prerequisite-patch-id: f36fad7a6eb02bf1b3c1171a61cbb854794bdf63
prerequisite-patch-id: 03a4a6747171c25f622df537a7608a4058acfc2c
prerequisite-patch-id: 3a87a035ec7c5f8773a6a7e5085ff19228263b2d
prerequisite-patch-id: 8483765548e3cdbd16e0a9ef44e9c60941611b12
prerequisite-patch-id: 6643c2dbd00ab86e742ef5a15f4d23c039575f07
prerequisite-patch-id: 9f288cab3b89ff67865b4e20c7b7f6f3835cec6f
prerequisite-patch-id: 6c8bae764061f224f8bf6bfb0a58b44689d1fb85
prerequisite-patch-id: c2d5675bad1219323ceb4f7c382dea8ef654256f
prerequisite-patch-id: f5fd02ee0a5960d146eba2f57ecf9ccb15a1b216
prerequisite-patch-id: d12cfa9299bb33218551b98efc8d2af8bb2ef321
prerequisite-patch-id: 889b86d3e246e3d6b4cd71e7e77571bc2bbaf45e
prerequisite-patch-id: a0f908f1aac5152622736d7589549682aabbdc72
prerequisite-patch-id: 92f4f7c0df22746ab9dcf4c84bc14f25f5043dc2
prerequisite-patch-id: 172d56f9145b9ec517bb8ff3e33b33c6a2c39786
prerequisite-patch-id: f374a92609437c1cd7bf2e247c287f126d337a02
prerequisite-patch-id: 2d540c940f6a6e05946e9ba2ca12a3fb28135e8c
prerequisite-patch-id: 24b5f0ec2a4f445e827caf1f4a95a80b0a9f7034
prerequisite-change-id: 20261101-work-procfs-fs-41f9fdc489cb:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
prerequisite-patch-id: 504e13cb7af5da6f3c8503f9336116ddd6ee9fc0
prerequisite-patch-id: 079f5420c7c6660679b25a93ab2912b42af19d6d
prerequisite-patch-id: 717bfde0d4141e875562d62b0e3c22d687517462
prerequisite-patch-id: 3e465d93cacbb875c5508b106bcaae53665de29e
prerequisite-patch-id: daa2e27b0b2dbf5ac04776bf03b0953d9f10bcbb
prerequisite-patch-id: a293472d78b43026dacbfe22a34ba1f8f2626e63
prerequisite-patch-id: f0a09eebade394217c88730e272d7bd33616f982
prerequisite-patch-id: 8471e839ad125d2f4cd9072486ae7da137619c1b
prerequisite-patch-id: 16433e5bde53510f9e6b7e04db2279bd0a8f63f5
prerequisite-patch-id: 03d349761a5a56d223067b051b1a38d594006ae2
prerequisite-patch-id: ffc6f41124e66357a7872aa1553e5404a7d48a55
prerequisite-patch-id: 901a0c1b4c2da010722471826fbfc51402ab8573
prerequisite-patch-id: 1204b4883154dea8cb7d93efadb9f49e70ecd7a8
prerequisite-patch-id: d2762d5dd1254bf7cf89a16b317b7b421718935f
prerequisite-patch-id: d1337f7a08fd4758a94bc5b2faeb30cbad1fe9cf
prerequisite-patch-id: a1d46785e75f0ec87cd12807cb57adc869a7f6a8
prerequisite-patch-id: 44c5d2365c5237b44a0162be9e73dcb392deab2c
prerequisite-patch-id: ad7ca39e7946dbf9e9ed4677b577bb5efad15af5
prerequisite-patch-id: 3984bbb1dbd74d87215a789483a75e968e81b453
prerequisite-patch-id: 48c81c042a9252249b32613e94f6bbca2fcb64b5
prerequisite-patch-id: 4d97d31af7bca868bf68a61fe7825dcbd7cc500b
prerequisite-patch-id: 227908b78f668bc6301cfa2217fa581471176b0f
prerequisite-patch-id: b4cbc3d04d64c061cc9cf2d22412ab5b4b37baaa
prerequisite-patch-id: fd779ec9acd1cd56b7eb9176cd0a10a548133f0c
prerequisite-patch-id: 5c61093340a745890222477d54f21e1121643c95
prerequisite-patch-id: 1199e9ee338002117fbe257118ff264e64eec0bb
prerequisite-patch-id: 08be0388a5aafb66919d0d678380c33f092738ce
prerequisite-patch-id: f98799e2973376543e67ae7a93ab62a20aa29564
prerequisite-patch-id: f670bed1eba8e1440bbfed164fb0c367f248e231
prerequisite-patch-id: f87d26787b356816be42fe8452d0262857d347b9
prerequisite-patch-id: 88a5543ceb70d27bd05b718480334d0a28133697
prerequisite-patch-id: 544f65704decf1a67848c8dc68ac60c5b76cdb81
prerequisite-patch-id: f36fad7a6eb02bf1b3c1171a61cbb854794bdf63
prerequisite-patch-id: 03a4a6747171c25f622df537a7608a4058acfc2c
prerequisite-patch-id: 3a87a035ec7c5f8773a6a7e5085ff19228263b2d
prerequisite-patch-id: 8483765548e3cdbd16e0a9ef44e9c60941611b12
prerequisite-patch-id: 6643c2dbd00ab86e742ef5a15f4d23c039575f07
prerequisite-patch-id: 9f288cab3b89ff67865b4e20c7b7f6f3835cec6f
prerequisite-patch-id: 6c8bae764061f224f8bf6bfb0a58b44689d1fb85
prerequisite-patch-id: c2d5675bad1219323ceb4f7c382dea8ef654256f
prerequisite-patch-id: f5fd02ee0a5960d146eba2f57ecf9ccb15a1b216
prerequisite-patch-id: d12cfa9299bb33218551b98efc8d2af8bb2ef321
prerequisite-patch-id: 889b86d3e246e3d6b4cd71e7e77571bc2bbaf45e
prerequisite-patch-id: a0f908f1aac5152622736d7589549682aabbdc72
prerequisite-patch-id: 92f4f7c0df22746ab9dcf4c84bc14f25f5043dc2
prerequisite-patch-id: 172d56f9145b9ec517bb8ff3e33b33c6a2c39786
prerequisite-patch-id: f374a92609437c1cd7bf2e247c287f126d337a02
prerequisite-patch-id: 2d540c940f6a6e05946e9ba2ca12a3fb28135e8c
prerequisite-patch-id: 24b5f0ec2a4f445e827caf1f4a95a80b0a9f7034
prerequisite-patch-id: e1136dd06b641700522373064fc4f0b8988019d2
prerequisite-patch-id: 1f93c44de1de16d56b63f242e11c61eb99fb839e
prerequisite-patch-id: 9e05d183b1de52caab2cfdfc3ddf204626166018
prerequisite-patch-id: f5e3b4966dc89516136a95cd4cc112a247737306
prerequisite-patch-id: a6e9771994c9e7839f6346ce84b88aa76b1fbb94
prerequisite-patch-id: 5cdbf669ab8cb5aae9695872b95cedcc895e8920
prerequisite-patch-id: 1181569f72ebcfd92fc854891a4cab295c99fd94
prerequisite-patch-id: 51fef3e3ccf3c0de31f96ace299dc6d1960af10b
prerequisite-patch-id: 2c3465f99c412708e4dd74d08a59c584d38cd011
prerequisite-patch-id: 4c2dd5a6b6956f87252fa471bfbdbec2f93e261f
prerequisite-patch-id: 637fd7a493983a181121f23dd2a9894bb941ea6e
prerequisite-patch-id: 7922f04bbdfc10776b16363f2414a179a168842b
prerequisite-patch-id: fbeeb1ac52cfcbd92b9670b4e69b948e80c874b6
prerequisite-patch-id: 76ce3f750a3c747b6dbbe4fe8dfca721504ff9e7
prerequisite-patch-id: 99e82aa0b1df251a7d4568cdfa605589cd726f02
prerequisite-patch-id: bf20bda16cfcdadcde5c4a22b8020fa1525c206b
prerequisite-patch-id: 7d31311fd97ddb0b2833c153f22855a39516be16
prerequisite-patch-id: ab46e417566b7997d43cc540d670892ffa186526
prerequisite-patch-id: a1a7ca09cabb1f3bde983a8f249865cfb33ffba9
prerequisite-patch-id: 5d507b2ac0f54617dd7bcc0ebbe003696809cbfe
prerequisite-patch-id: 30b8a6a426dd7b9f466bde876a813a4e27c4a284
prerequisite-patch-id: 95ece6bf7b926859312be956bb9b0ba7bf1d274a
prerequisite-patch-id: 4a896ec0ba4ac506b1f6a010a05f703f1bf888b8
prerequisite-patch-id: 5914904497e4739e4e94d391968d547b375c4def
prerequisite-patch-id: f98a02b2dae4ad56aa7d11de0361ff86b1b60846
prerequisite-patch-id: c4ba3c61e396328d84731308a7fa49348191f2a2
prerequisite-patch-id: 1b836097aa8c6e35ca7a9f5cbb0aafab59153720
prerequisite-patch-id: a4ff1666fad32f9037d926cb5e37b338d2379d61
prerequisite-patch-id: fa65e32038043b8430248870d256e3eaa47f4d34
prerequisite-patch-id: 9a278cc30fac355264a1fd2d9739ebbfb8474b04
prerequisite-change-id: 20261101-work-procfs-net-bc8b21e3eff0:v2
prerequisite-patch-id: a81e8b894107e48d607f8257d2c9f56e0dd6f400
prerequisite-patch-id: 7edf7ca7ecd32c9e09085e4b65922af10097beaa
prerequisite-patch-id: 81f6893f79b4236637675553298a6f2892b603f3
prerequisite-patch-id: 598c2b1a389f47adcac88ebcf1c9f74e2511fbab
prerequisite-patch-id: 6f5a2172dacc5ff2491fa9832c48ccd0e1ce1eda
prerequisite-patch-id: 8947af6490288e4e2a3b2bf8844a974bedb1d975
prerequisite-patch-id: 8cbe756286fd95967d31b0c46cacfeb05f0a2c6b
prerequisite-patch-id: 3fa159f2b6ccd0ac51a2662e4eec5587ec18de89
prerequisite-patch-id: bfb4e4ffe9631cb58015fefe6bd3698cd53e2244
prerequisite-patch-id: 56ff6667a57a962264c07c0227c61aa2f1f4c22c
prerequisite-patch-id: bc506323e29944ec0c29eae84950c706a8592042
prerequisite-patch-id: 326c0ebb5accf0f40cbee1323fb4c3378f5be154
prerequisite-patch-id: d6eaf7690a54a0dfda7500936a048b769fa265dd
prerequisite-patch-id: 7c7b2535642b4d388e13eab518cbe0f9550eb1e6
prerequisite-patch-id: 0474af12959624910718795bf86684383664c685
prerequisite-patch-id: f6d4191e23c22e2d2cc90cc5d04781f913e98a8e
prerequisite-patch-id: b0031a7c4855b7ec38259c59f30f65101a8fc4b5
prerequisite-patch-id: 0b7f226abf2b9ff41873a1aa55cf97747647d56b
prerequisite-patch-id: f63e345f897619af54813958046617c655fb7daf
prerequisite-patch-id: c0e21e762a2960e3324c5ab04634a7035e515fa6
prerequisite-patch-id: fd59c71eadd8f39c58b3baea93567bc093bc9b0e
prerequisite-patch-id: 5d52cc8a5c73e4c5ba16b8e24f51408c17583bf9
prerequisite-patch-id: 1f9179284e2f3314d4b46ac5e989089a21c7576c
prerequisite-patch-id: 10397bbf696bee16dc71eb79fff6c5e73842bcbc
prerequisite-patch-id: 9b44279dcf08912238d2f6438a3328a778a79a0c
prerequisite-patch-id: 16854b621a3a71dfc365aaf7abaa7f65adfe9f7e
prerequisite-patch-id: ca42eea21fae1fd1cd3518ab057c74b61ffd68fe
prerequisite-patch-id: 23255dc2be76b0479c083dbd4c897bfbb533aed5
prerequisite-patch-id: 82129c687ebf0a41b369893b92f2c038420ab801
prerequisite-patch-id: 56ad57a99a5bda075a9f4e844368974296744934
prerequisite-patch-id: 288b3cbaa11e01a778cc3d7beb6c0549aacf59f2
prerequisite-patch-id: a163b1549608652bfa5bd9ff93efa55b541010c4
prerequisite-patch-id: 43b92dfc1a98fbf0d14597a3e3ae99972844773b
prerequisite-patch-id: 19c12bc6e3fbed35acc1f657196b1a997f48cdfe
prerequisite-patch-id: 5800c3076694bad719954b2ad4d7448c6e013bfd
prerequisite-patch-id: 2a2f63d8843b159594b9eee6ddea028ce76a6270
prerequisite-patch-id: 40a1951d57906c4a1b98a4bd96a814b80339b9c5
prerequisite-patch-id: e2141077e69f20a2b27fab69c8d61d0686682f53
prerequisite-patch-id: c4d6018c26c40dc549d88330d23ce48f872c2b7f
prerequisite-patch-id: 6de8ec17746031bc6d1d9ac262c5be0f905fcd79
prerequisite-patch-id: b87bcb167884605bff1fd0f2ed8a88942d07efd5
prerequisite-patch-id: cfa9a8b4c67e20cfd22d77035bfd21ee96ab3298
prerequisite-patch-id: abf3482ed2399b7b2e1ee72e937af05bb9200667
prerequisite-patch-id: 02c175b2dee565a85b3308ecf2ec8e3c9a029e0f
prerequisite-patch-id: d58c239fba616b366a725de6acba3f88734156d0
prerequisite-patch-id: dbe02fe3f784776fda5e7ae99f077bef0cd4b48d
prerequisite-patch-id: 53edc9a95afff57c4acba40095a8054924261ea2
prerequisite-patch-id: 5348d8957eb7eae7430ca8b101aa84ce77d3aa4f
prerequisite-patch-id: 36c96d781e2dd80b20932667bbe6e7fd14976069
prerequisite-patch-id: efeb2d6f7df71d5dede2c1d12fe999a28e38aab9
prerequisite-patch-id: 17f95c7fdf0bdc7c8aaaf7883bff1dcc19a0f529
prerequisite-patch-id: 117db27dcdef433de7c6be5e95973cac1e373927
prerequisite-patch-id: a0844aa26ffb65ccb362b88ef6c2f4758e15edbf
prerequisite-patch-id: 9c64355dfde62e399f2717d9208c4607834d4650
prerequisite-patch-id: 9644739854ddfe2876f17fda8727fd5119255957
prerequisite-patch-id: c61bba24c035f79a2a32a80ace0924ab58e97f46
prerequisite-patch-id: 143fb91bddf33068b6ee11e205818c4c2815e23d
prerequisite-patch-id: 9ce9be2ff05250f92d945c0084f4bb31d3d0b27d
prerequisite-patch-id: aee0961341523547095a43ae298cb8b551302f10
prerequisite-patch-id: 2f0fdb970ddd760d85ff5d2caad0b96348270182
prerequisite-patch-id: f2aa468ff5cbb1cabab3f70e1b8eeee0286cfb4a
prerequisite-patch-id: 5555895bcbca4d7c9888ecc9e82c0e4d76da8f40
prerequisite-patch-id: 487141c49e2548310bfb6c2a0964a78f08b285a9
prerequisite-patch-id: c3d3008819fa5629a18142ec9ba6d7024ade7fdb
prerequisite-patch-id: ca587c976690ac16e3d759fccab2116fef0508e8
prerequisite-patch-id: 9423f410b99853693db06c29f12f1c08278b050d
prerequisite-patch-id: e269815617a6324615a38916b8886f99d98c641e
prerequisite-patch-id: 3d24be1897a624d519ef144801f76d152c7528a9
prerequisite-patch-id: 1ea3fc8319d9012faaf3a182ac61d5da89aafdb7
prerequisite-patch-id: 7547b4e2c1b3588acf6caf90cc01fe7884fdb6bd
prerequisite-patch-id: 695d325349ebeb89bf0ea24bcf0c4f1c4edacab5
prerequisite-patch-id: e33502a202979aba0d6fdaf196e8471d906992a1
prerequisite-patch-id: 47bfe4f07677ad75fe8d9accc8923a1cbdf3afa6
prerequisite-patch-id: 9fc0739226572203fcb36f2c271be7b27f405ef2
prerequisite-patch-id: 504e13cb7af5da6f3c8503f9336116ddd6ee9fc0
prerequisite-patch-id: 079f5420c7c6660679b25a93ab2912b42af19d6d
prerequisite-patch-id: 717bfde0d4141e875562d62b0e3c22d687517462
prerequisite-patch-id: 3e465d93cacbb875c5508b106bcaae53665de29e
prerequisite-patch-id: daa2e27b0b2dbf5ac04776bf03b0953d9f10bcbb
prerequisite-patch-id: a293472d78b43026dacbfe22a34ba1f8f2626e63
prerequisite-patch-id: f0a09eebade394217c88730e272d7bd33616f982
prerequisite-patch-id: 8471e839ad125d2f4cd9072486ae7da137619c1b
prerequisite-patch-id: 16433e5bde53510f9e6b7e04db2279bd0a8f63f5
prerequisite-patch-id: 03d349761a5a56d223067b051b1a38d594006ae2
prerequisite-patch-id: ffc6f41124e66357a7872aa1553e5404a7d48a55
prerequisite-patch-id: 901a0c1b4c2da010722471826fbfc51402ab8573
prerequisite-patch-id: 1204b4883154dea8cb7d93efadb9f49e70ecd7a8
prerequisite-patch-id: d2762d5dd1254bf7cf89a16b317b7b421718935f
prerequisite-patch-id: d1337f7a08fd4758a94bc5b2faeb30cbad1fe9cf
prerequisite-patch-id: a1d46785e75f0ec87cd12807cb57adc869a7f6a8
prerequisite-patch-id: 44c5d2365c5237b44a0162be9e73dcb392deab2c
prerequisite-patch-id: ad7ca39e7946dbf9e9ed4677b577bb5efad15af5
prerequisite-patch-id: 3984bbb1dbd74d87215a789483a75e968e81b453
prerequisite-patch-id: 48c81c042a9252249b32613e94f6bbca2fcb64b5
prerequisite-patch-id: 4d97d31af7bca868bf68a61fe7825dcbd7cc500b
prerequisite-patch-id: 227908b78f668bc6301cfa2217fa581471176b0f
prerequisite-patch-id: b4cbc3d04d64c061cc9cf2d22412ab5b4b37baaa
prerequisite-patch-id: fd779ec9acd1cd56b7eb9176cd0a10a548133f0c
prerequisite-patch-id: 5c61093340a745890222477d54f21e1121643c95
prerequisite-patch-id: 1199e9ee338002117fbe257118ff264e64eec0bb
prerequisite-patch-id: 08be0388a5aafb66919d0d678380c33f092738ce
prerequisite-patch-id: f98799e2973376543e67ae7a93ab62a20aa29564
prerequisite-patch-id: f670bed1eba8e1440bbfed164fb0c367f248e231
prerequisite-patch-id: f87d26787b356816be42fe8452d0262857d347b9
prerequisite-patch-id: 88a5543ceb70d27bd05b718480334d0a28133697
prerequisite-patch-id: 544f65704decf1a67848c8dc68ac60c5b76cdb81
prerequisite-patch-id: f36fad7a6eb02bf1b3c1171a61cbb854794bdf63
prerequisite-patch-id: 03a4a6747171c25f622df537a7608a4058acfc2c
prerequisite-patch-id: 3a87a035ec7c5f8773a6a7e5085ff19228263b2d
prerequisite-patch-id: 8483765548e3cdbd16e0a9ef44e9c60941611b12
prerequisite-patch-id: 6643c2dbd00ab86e742ef5a15f4d23c039575f07
prerequisite-patch-id: 9f288cab3b89ff67865b4e20c7b7f6f3835cec6f
prerequisite-patch-id: 6c8bae764061f224f8bf6bfb0a58b44689d1fb85
prerequisite-patch-id: c2d5675bad1219323ceb4f7c382dea8ef654256f
prerequisite-patch-id: f5fd02ee0a5960d146eba2f57ecf9ccb15a1b216
prerequisite-patch-id: d12cfa9299bb33218551b98efc8d2af8bb2ef321
prerequisite-patch-id: 889b86d3e246e3d6b4cd71e7e77571bc2bbaf45e
prerequisite-patch-id: a0f908f1aac5152622736d7589549682aabbdc72
prerequisite-patch-id: 92f4f7c0df22746ab9dcf4c84bc14f25f5043dc2
prerequisite-patch-id: 172d56f9145b9ec517bb8ff3e33b33c6a2c39786
prerequisite-patch-id: f374a92609437c1cd7bf2e247c287f126d337a02
prerequisite-patch-id: 2d540c940f6a6e05946e9ba2ca12a3fb28135e8c
prerequisite-patch-id: 24b5f0ec2a4f445e827caf1f4a95a80b0a9f7034
prerequisite-patch-id: e1136dd06b641700522373064fc4f0b8988019d2
prerequisite-patch-id: 1f93c44de1de16d56b63f242e11c61eb99fb839e
prerequisite-patch-id: 9e05d183b1de52caab2cfdfc3ddf204626166018
prerequisite-patch-id: f5e3b4966dc89516136a95cd4cc112a247737306
prerequisite-patch-id: a6e9771994c9e7839f6346ce84b88aa76b1fbb94
prerequisite-patch-id: 5cdbf669ab8cb5aae9695872b95cedcc895e8920
prerequisite-patch-id: 1181569f72ebcfd92fc854891a4cab295c99fd94
prerequisite-patch-id: 51fef3e3ccf3c0de31f96ace299dc6d1960af10b
prerequisite-patch-id: 2c3465f99c412708e4dd74d08a59c584d38cd011
prerequisite-patch-id: 4c2dd5a6b6956f87252fa471bfbdbec2f93e261f
prerequisite-patch-id: 637fd7a493983a181121f23dd2a9894bb941ea6e
prerequisite-patch-id: 7922f04bbdfc10776b16363f2414a179a168842b
prerequisite-patch-id: fbeeb1ac52cfcbd92b9670b4e69b948e80c874b6
prerequisite-patch-id: 76ce3f750a3c747b6dbbe4fe8dfca721504ff9e7
prerequisite-patch-id: 99e82aa0b1df251a7d4568cdfa605589cd726f02
prerequisite-patch-id: bf20bda16cfcdadcde5c4a22b8020fa1525c206b
prerequisite-patch-id: 7d31311fd97ddb0b2833c153f22855a39516be16
prerequisite-patch-id: ab46e417566b7997d43cc540d670892ffa186526
prerequisite-patch-id: a1a7ca09cabb1f3bde983a8f249865cfb33ffba9
prerequisite-patch-id: 5d507b2ac0f54617dd7bcc0ebbe003696809cbfe
prerequisite-patch-id: 30b8a6a426dd7b9f466bde876a813a4e27c4a284
prerequisite-patch-id: 95ece6bf7b926859312be956bb9b0ba7bf1d274a
prerequisite-patch-id: 4a896ec0ba4ac506b1f6a010a05f703f1bf888b8
prerequisite-patch-id: 5914904497e4739e4e94d391968d547b375c4def
prerequisite-patch-id: f98a02b2dae4ad56aa7d11de0361ff86b1b60846
prerequisite-patch-id: c4ba3c61e396328d84731308a7fa49348191f2a2
prerequisite-patch-id: 1b836097aa8c6e35ca7a9f5cbb0aafab59153720
prerequisite-patch-id: a4ff1666fad32f9037d926cb5e37b338d2379d61
prerequisite-patch-id: fa65e32038043b8430248870d256e3eaa47f4d34
prerequisite-patch-id: 9a278cc30fac355264a1fd2d9739ebbfb8474b04
prerequisite-patch-id: ed86b546d44c9d5612a132b8f188a1727bf20140
prerequisite-patch-id: 3531ac7c29c6d31f5c4d7830eec493700c7817cc
prerequisite-patch-id: d5636a3c6c5d806cac00791c49bf3703b2a61c7d
prerequisite-patch-id: a789b6da4762c80e4e223d6f20db32a4812cd87b
prerequisite-patch-id: 96c2d266089780f6a0b07f54da812b87b5749abd
prerequisite-patch-id: 51e5bdc34987e2266e8801368e622566ccf20968
prerequisite-patch-id: 48b7e3fe2d9ce6c61b8b7d34ad26ecf0bfcf53cc
prerequisite-patch-id: f39c6af65cc5b209517939533a7cb9cc1ee03da0
prerequisite-patch-id: 9e2cccf47b8c293ebef941d1268956901f1dd323
prerequisite-patch-id: 3d0d826b755fabb6f5ceef6f74ca50777ae1c64c
prerequisite-patch-id: 0126190ba10aa140572e0a652c91d1de7fae0106
prerequisite-patch-id: c0de7f6bcf931394d46239405296ce7008f7a095
prerequisite-patch-id: b8c2dd4243818acc67a9e3917c528a4f6decb498
Christian Brauner
maintainerPATCH RESEND v2 1/6 proc: drop ->proc_write()
Every writable entry implements ->proc_write_buf() now and procfs copies in what is written before it pins the entry. Remove ->proc_write().
--- fs/proc/generic.c | 2 -- fs/proc/inode.c | 15 +-------------- include/linux/proc_fs.h | 1 - 3 files changed, 1 insertion(+), 17 deletions(-)
fs/proc/generic.c +0 -2
@@ -473,8 +473,6 @@ static int pde_set_flags(struct proc_dir_entry *pde)if (proc_ops->proc_mmap) pde->flags |= PROC_ENTRY_proc_mmap;if (proc_ops->proc_write_buf) { -if (WARN_ON_ONCE (proc_ops->proc_write)) -return -EINVAL ; pde->flags |= PROC_ENTRY_proc_write_buf; pde->write_size = proc_ops->proc_write_size ?:PAGE_SIZE -1 ;if (proc_ops->proc_flags &PROC_ENTRY_SHORT_WRITES )
fs/proc/inode.c +1 -14
@@ -508,14 +508,6 @@ static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count,return rv; } -static ssize_t pde_write (struct proc_dir_entry *pde,struct file *file,const char __user *buf,size_t count,loff_t *ppos) -{ - const auto write = pde->proc_ops->proc_write; -if (write) -return write (file, buf, count, ppos); -return -EIO ; -} -/* * procfs copies in what is written before it pins the entry. A writer that * faults on its buffer then doesn't hold up remove_proc_entry().
@@ -550,15 +542,10 @@ static ssize_t pde_write_buf(struct proc_dir_entry *pde, struct file *file,static ssize_t proc_reg_write (struct file *file,const char __user *buf,size_t count,loff_t *ppos) {struct proc_dir_entry *pde =PDE (file_inode (file)); -ssize_t rv;if (pde_has_proc_write_buf (pde))return pde_write_buf (pde, file, buf, count, ppos); -if (!pde_pin (pde)) -return -EIO ; - rv =pde_write (pde, file, buf, count, ppos); -pde_unpin (pde); -return rv; +return -EIO ; }/*
include/linux/proc_fs.h +0 -1
@@ -77,7 +77,6 @@ struct proc_ops {int (*proc_open)(struct inode *,struct file *);ssize_t (*proc_read)(struct file *,char __user *,size_t ,loff_t *);ssize_t (*proc_read_iter)(struct kiocb *,struct iov_iter *); -ssize_t (*proc_write)(struct file *,const char __user *,size_t ,loff_t *);/* * mandatory unless nonseekable_open() or equivalent is used, procfs * seeks seq_file entries itself
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 2/6 proc: drop ->proc_ioctl() and ->proc_compat_ioctl()
In reply to Christian BraunerEvery entry with ioctls implements ->proc_ioctl_buf() now and procfs copies the arguments in and out around pinning the entry, for 32-bit tasks too. Remove ->proc_ioctl() and ->proc_compat_ioctl().
--- fs/proc/generic.c | 7 ------- fs/proc/inode.c | 30 ++---------------------------- include/linux/proc_fs.h | 4 ---- 3 files changed, 2 insertions(+), 39 deletions(-)
fs/proc/generic.c +0 -7
@@ -488,13 +488,6 @@ static int pde_set_flags(struct proc_dir_entry *pde) pde->flags |=PROC_ENTRY_FULL_READS ; }if (proc_ops->proc_ioctl_buf) { -if (WARN_ON_ONCE (proc_ops->proc_ioctl)) -return -EINVAL ; -#ifdef CONFIG_COMPAT -/* 32-bit tasks go through the table as well */ -if (WARN_ON_ONCE (proc_ops->proc_compat_ioctl)) -return -EINVAL ; -#endif /* the table says what procfs copies, see pde_ioctl_arg() */ if (WARN_ON_ONCE (!proc_ops->proc_ioctl_args || !proc_ops->proc_nr_ioctl_args))
fs/proc/inode.c +2 -28
@@ -588,14 +588,6 @@ void proc_poll_notify(struct proc_dir_entry *pde) }EXPORT_SYMBOL_GPL (proc_poll_notify); -static long pde_ioctl (struct proc_dir_entry *pde,struct file *file,unsigned int cmd,unsigned long arg) -{ - const auto ioctl = pde->proc_ops->proc_ioctl; -if (ioctl) -return ioctl (file, cmd, arg); -return -ENOTTY ; -} -/* the table lives in proc_ops, which goes away with the entry */ static bool pde_ioctl_arg (struct proc_dir_entry *pde,unsigned int cmd,struct proc_ioctl_arg *arg)
@@ -652,38 +644,20 @@ static long pde_ioctl_buf(struct proc_dir_entry *pde, struct file *file,static long proc_reg_unlocked_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {struct proc_dir_entry *pde =PDE (file_inode (file)); -long rv;if (pde_has_proc_ioctl_buf (pde))return pde_ioctl_buf (pde, file, cmd, (void __user *)arg, arg); -if (!pde_pin (pde)) -return -ENOTTY ; - rv =pde_ioctl (pde, file, cmd, arg); -pde_unpin (pde); -return rv; -} - -#ifdef CONFIG_COMPAT -static long pde_compat_ioctl (struct proc_dir_entry *pde,struct file *file,unsigned int cmd,unsigned long arg) -{ - const auto compat_ioctl = pde->proc_ops->proc_compat_ioctl; -if (compat_ioctl) -return compat_ioctl (file, cmd, arg);return -ENOTTY ; } +#ifdef CONFIG_COMPAT static long proc_reg_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {struct proc_dir_entry *pde =PDE (file_inode (file)); -long rv;if (pde_has_proc_ioctl_buf (pde))return pde_ioctl_buf (pde, file, cmd,compat_ptr (arg), arg); -if (!pde_pin (pde)) -return -ENOTTY ; - rv =pde_compat_ioctl (pde, file, cmd, arg); -pde_unpin (pde); -return rv; +return -ENOTTY ; }#else #define proc_reg_compat_ioctl NULL
include/linux/proc_fs.h +0 -4
@@ -90,10 +90,6 @@ struct proc_ops {* entry reports EPOLLERR | EPOLLPRI. */ __poll_t (*proc_poll)(struct file *,struct poll_table_struct *); -long (*proc_ioctl)(struct file *,unsigned int ,unsigned long ); -#ifdef CONFIG_COMPAT -long (*proc_compat_ioctl)(struct file *,unsigned int ,unsigned long ); -#endif /* * procfs pins the entry around ->proc_mmap() and wraps the * vm_operations of the mapping so that ->open(), ->fault(),
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 3/6 proc: give kcore, kmsg and the kpage files their own file_operations
In reply to Christian Braunerkcore, kmsg, kpagecount, kpageflags and kpagecgroup are the entries that keep reading straight into userspace. They can, procfs never pins them, they're built in and never removed. They are also the only reason struct proc_ops still has two methods that get a __user pointer, ->proc_read() and ->proc_read_iter(), and the only reason procfs has three sets of file_operations for regular files.
So give them a file_operations of their own and let proc_get_inode() put that into the inode as it is. procfs doesn't mediate them at all then, which is what being permanent and copying to userspace yourself amounts to anyway. proc_create_fops() is internal to fs/proc, nothing outside of it can register such an entry, and it marks the entry permanent, so it can't be removed either.
What changes for them: mmap() fails with -ENODEV instead of -EIO, there is no ->mmap now where procfs used to answer for the missing ->proc_mmap(), and a write() by someone who can open them for writing fails with -EINVAL instead of -EIO, for the same reason. kcore keeps splice_read(), the other four never had it.
--- fs/proc/generic.c | 25 ++++++++++++++++++++++++- fs/proc/inode.c | 4 +++- fs/proc/internal.h | 10 ++++++++++ fs/proc/kcore.c | 14 +++++++------- fs/proc/kmsg.c | 17 +++++++++-------- fs/proc/page.c | 27 ++++++++++++--------------- include/linux/proc_fs.h | 1 + 7 files changed, 66 insertions(+), 32 deletions(-)
fs/proc/generic.c +24 -1
@@ -436,6 +436,9 @@ static int pde_set_flags(struct proc_dir_entry *pde) {const struct proc_ops *proc_ops = pde->proc_ops; +/* nothing of this applies to these, see proc_create_fops() */ +if (pde_has_proc_fops (pde)) +return 0 ;if (!proc_ops)return 0 ;
@@ -505,7 +508,7 @@ static int pde_init_open_node(struct proc_dir_entry *pde) {struct pde_open_node *on; -if (!S_ISREG (pde->mode)) +if (!S_ISREG (pde->mode) ||pde_has_proc_fops (pde))return 0 ;if (!pde_has_proc_poll (pde) && !pde_tracks_files (pde))return 0 ;
@@ -795,6 +798,26 @@ struct proc_dir_entry *proc_create(const char *name, umode_t mode, }EXPORT_SYMBOL (proc_create); +/* +* For the built-in entries that read straight into userspace and are never +* removed, kcore, kmsg and the kpage files. procfs doesn't mediate these at +* all, their file_operations go into the inode as they are. Not exported on +* purpose, everything else uses struct proc_ops. +*/ +struct proc_dir_entry *proc_create_fops (const char *name,umode_t mode, +struct proc_dir_entry *parent,const struct file_operations *fops) +{ +struct proc_dir_entry *p; + + p =proc_create_reg (name, mode, &parent,NULL ); +if (!p) +return NULL ; + p->proc_fops = fops; + p->flags |= PROC_ENTRY_proc_fops; +pde_make_permanent (p); +return proc_register (parent, p,NULL ); +} +/* procfs owns the seq_file of these, see pde_seq_start() */ static const struct proc_ops proc_seq_ops = {/* not permanent -- can call into arbitrary seq_operations */
fs/proc/inode.c +3 -1
@@ -1024,7 +1024,9 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)if (S_ISREG (inode->i_mode)) { inode->i_op = de->proc_iops; -if (pde_is_seq_file (de)) +if (pde_has_proc_fops (de)) + inode->i_fop = de->proc_fops; +else if (pde_is_seq_file (de)) inode->i_fop = &proc_seq_file_ops;else if (pde_has_proc_read_iter (de) ||pde_has_proc_read_buf (de)) inode->i_fop = &proc_iter_file_ops;
fs/proc/internal.h +10 -0
@@ -41,6 +41,8 @@ struct proc_dir_entry {union {const struct proc_ops *proc_ops;const struct file_operations *proc_dir_ops; +/* of a permanent entry procfs doesn't mediate, see proc_create_fops() */ +const struct file_operations *proc_fops; };union {const struct seq_operations *seq_ops;
@@ -96,6 +98,11 @@ static inline void pde_make_permanent(struct proc_dir_entry *pde) pde->flags |=PROC_ENTRY_PERMANENT ; } +static inline bool pde_has_proc_fops (const struct proc_dir_entry *pde) +{ +return pde->flags & PROC_ENTRY_proc_fops; +} +static inline bool pde_has_proc_read_iter (const struct proc_dir_entry *pde) {return pde->flags & PROC_ENTRY_proc_read_iter;
@@ -352,6 +359,9 @@ bool proc_fill_cache(struct file *, struct dir_context *, const char *, unsigned*/ struct proc_dir_entry *proc_create_reg (const char *name,umode_t mode,struct proc_dir_entry **parent,void *data); +struct proc_dir_entry *proc_create_fops (const char *name,umode_t mode, +struct proc_dir_entry *parent, +const struct file_operations *fops);struct proc_dir_entry *proc_register (struct proc_dir_entry *dir,struct proc_dir_entry *dp,struct lock_class_key *key);
fs/proc/kcore.c +7 -7
@@ -664,12 +664,12 @@ static int release_kcore(struct inode *inode, struct file *file)return 0 ; } -static const struct proc_ops kcore_proc_ops = { - .proc_flags =PROC_ENTRY_PERMANENT , - .proc_read_iter = read_kcore_iter, - .proc_open = open_kcore, - .proc_release = release_kcore, - .proc_lseek = default_llseek, +static const struct file_operations kcore_fops = { + .read_iter = read_kcore_iter, + .splice_read = copy_splice_read, + .open = open_kcore, + .release = release_kcore, + .llseek = default_llseek, };/* just remember that we have to update kcore */
@@ -724,7 +724,7 @@ static void __init add_modules_range(void)static int __init proc_kcore_init (void ) { - proc_root_kcore =proc_create ("kcore" ,S_IRUSR ,NULL , &kcore_proc_ops); + proc_root_kcore =proc_create_fops ("kcore" ,S_IRUSR ,NULL , &kcore_fops);if (!proc_root_kcore) {pr_err ("couldn't create /proc/kcore\n" );return 0 ;/* Always returns 0. */
fs/proc/kmsg.c +9 -8
@@ -17,6 +17,8 @@#include <asm/io.h> +#include "internal.h" +static int kmsg_open (struct inode * inode,struct file * file) {return do_syslog (SYSLOG_ACTION_OPEN ,NULL ,0 ,SYSLOG_FROM_PROC );
@@ -46,18 +48,17 @@ static __poll_t kmsg_poll(struct file *file, poll_table *wait) } -static const struct proc_ops kmsg_proc_ops = { - .proc_flags =PROC_ENTRY_PERMANENT , - .proc_read = kmsg_read, - .proc_poll = kmsg_poll, - .proc_open = kmsg_open, - .proc_release = kmsg_release, - .proc_lseek = generic_file_llseek, +static const struct file_operations proc_kmsg_fops = { + .read = kmsg_read, + .poll = kmsg_poll, + .open = kmsg_open, + .release = kmsg_release, + .llseek = generic_file_llseek, };static int __init proc_kmsg_init (void ) { -proc_create ("kmsg" ,S_IRUSR ,NULL , &kmsg_proc_ops); +proc_create_fops ("kmsg" ,S_IRUSR ,NULL , &proc_kmsg_fops);return 0 ; }fs_initcall (proc_kmsg_init);
fs/proc/page.c +12 -15
@@ -130,10 +130,9 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,return kpage_read (file, buf, count, ppos,KPAGE_COUNT ); } -static const struct proc_ops kpagecount_proc_ops = { - .proc_flags =PROC_ENTRY_PERMANENT , - .proc_lseek = mem_lseek, - .proc_read = kpagecount_read, +static const struct file_operations kpagecount_fops = { + .llseek = mem_lseek, + .read = kpagecount_read, };
@@ -256,10 +255,9 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf,return kpage_read (file, buf, count, ppos,KPAGE_FLAGS ); } -static const struct proc_ops kpageflags_proc_ops = { - .proc_flags =PROC_ENTRY_PERMANENT , - .proc_lseek = mem_lseek, - .proc_read = kpageflags_read, +static const struct file_operations kpageflags_fops = { + .llseek = mem_lseek, + .read = kpageflags_read, };#ifdef CONFIG_MEMCG
@@ -268,19 +266,18 @@ static ssize_t kpagecgroup_read(struct file *file, char __user *buf, {return kpage_read (file, buf, count, ppos,KPAGE_CGROUP ); } -static const struct proc_ops kpagecgroup_proc_ops = { - .proc_flags =PROC_ENTRY_PERMANENT , - .proc_lseek = mem_lseek, - .proc_read = kpagecgroup_read, +static const struct file_operations kpagecgroup_fops = { + .llseek = mem_lseek, + .read = kpagecgroup_read, };#endif /* CONFIG_MEMCG */ static int __init proc_page_init (void ) { -proc_create ("kpagecount" ,S_IRUSR ,NULL , &kpagecount_proc_ops); -proc_create ("kpageflags" ,S_IRUSR ,NULL , &kpageflags_proc_ops); +proc_create_fops ("kpagecount" ,S_IRUSR ,NULL , &kpagecount_fops); +proc_create_fops ("kpageflags" ,S_IRUSR ,NULL , &kpageflags_fops);#ifdef CONFIG_MEMCG -proc_create ("kpagecgroup" ,S_IRUSR ,NULL , &kpagecgroup_proc_ops); +proc_create_fops ("kpagecgroup" ,S_IRUSR ,NULL , &kpagecgroup_fops);#endif return 0 ; }
include/linux/proc_fs.h +1 -0
@@ -27,6 +27,7 @@ enum {#endif PROC_ENTRY_proc_read_iter =1U <<1 , + PROC_ENTRY_proc_fops =1U <<2 , PROC_ENTRY_proc_lseek =1U <<3 , PROC_ENTRY_proc_seq_ops =1U <<4 , PROC_ENTRY_proc_show = 1U << 5,
Signature · 1 line
2.53.0
Christian Brauner
maintainerPATCH RESEND v2 4/6 proc: drop ->proc_read() and ->proc_read_iter()
In reply to Christian BraunerNothing implements them anymore. Every entry that can be removed fills procfs' buffer through ->proc_read_buf() or is a seq_file entry, and the permanent ones that still read straight into userspace have file_operations of their own now.
With them go the flag, the registration checks that kept them apart from ->proc_read_buf() and the seq_file entries, proc_reg_read(), and two of the three sets of file_operations for regular files:proc_reg_llseek() and proc_reg_read_iter() hand a seq_file entry to seq_lseek() and seq_read_iter() themselves now, like kernfs_fop_read_iter() does, so one set serves every entry that has proc_ops. That set has ->splice_read(), so a splice() from an entry that can't be read at all, a write-only one, fails with -EIO now instead of -EINVAL.
Nothing in struct proc_ops takes a __user pointer anymore.
--- fs/proc/generic.c | 14 ++++------ fs/proc/inode.c | 69 +++++-------------------------------------------- fs/proc/internal.h | 5 ---- include/linux/proc_fs.h | 4 +-- 4 files changed, 12 insertions(+), 80 deletions(-)
fs/proc/generic.c +5 -9
@@ -454,8 +454,7 @@ static int pde_set_flags(struct proc_dir_entry *pde) }if (pde_is_seq_file (pde)) {/* procfs reads and seeks through the seq_file itself */ -if (WARN_ON_ONCE (proc_ops->proc_read || proc_ops->proc_read_iter || - proc_ops->proc_lseek)) +if (WARN_ON_ONCE (proc_ops->proc_lseek))return -EINVAL ;/* and frees it, see pde_seq_release() */ if (WARN_ON_ONCE(proc_ops->proc_release == seq_release ||
@@ -463,11 +462,8 @@ static int pde_set_flags(struct proc_dir_entry *pde) proc_ops->proc_release == single_release))return -EINVAL ; pde->flags |= PROC_ENTRY_proc_lseek; - }else { -if (proc_ops->proc_read_iter) - pde->flags |= PROC_ENTRY_proc_read_iter; -if (proc_ops->proc_lseek) - pde->flags |= PROC_ENTRY_proc_lseek; + }else if (proc_ops->proc_lseek) { + pde->flags |= PROC_ENTRY_proc_lseek; }if (proc_ops->proc_poll) pde->flags |= PROC_ENTRY_proc_poll;
@@ -482,8 +478,8 @@ static int pde_set_flags(struct proc_dir_entry *pde) pde->flags |=PROC_ENTRY_SHORT_WRITES ; }if (proc_ops->proc_read_buf) { -if (WARN_ON_ONCE (pde_is_seq_file (pde) || proc_ops->proc_read || - proc_ops->proc_read_iter)) +/* procfs reads through the seq_file itself */ +if (WARN_ON_ONCE (pde_is_seq_file (pde)))return -EINVAL ; pde->flags |= PROC_ENTRY_proc_read_buf; pde->read_size = proc_ops->proc_read_size ?:PAGE_SIZE ;
fs/proc/inode.c +6 -63
100 lines not on this page · raw message
fs/proc/internal.h +0 -5
@@ -103,11 +103,6 @@ static inline bool pde_has_proc_fops(const struct proc_dir_entry *pde)return pde->flags & PROC_ENTRY_proc_fops; } -static inline bool pde_has_proc_read_iter (const struct proc_dir_entry *pde) -{ -return pde->flags & PROC_ENTRY_proc_read_iter; -} -static inline bool pde_has_proc_lseek (const struct proc_dir_entry *pde) {return pde->flags & PROC_ENTRY_proc_lseek;
include/linux/proc_fs.h +1 -3
@@ -17,6 +17,7 @@ struct seq_operations;enum {/* * All /proc entries using this ->proc_ops instance are never removed. +* procfs calls into them without pinning them. * * If in doubt, ignore this flag. */
@@ -26,7 +27,6 @@ enum {PROC_ENTRY_PERMANENT =1U <<0 , #endif - PROC_ENTRY_proc_read_iter =1U <<1 , PROC_ENTRY_proc_fops =1U <<2 , PROC_ENTRY_proc_lseek =1U <<3 , PROC_ENTRY_proc_seq_ops = 1U << 4,
@@ -76,8 +76,6 @@ struct proc_ioctl_arg {struct proc_ops {unsigned int proc_flags;int (*proc_open)(struct inode *,struct file *); -ssize_t (*proc_read)(struct file *,char __user *,size_t ,loff_t *); -ssize_t (*proc_read_iter)(struct kiocb *,struct iov_iter *);/* * mandatory unless nonseekable_open() or equivalent is used, procfs * seeks seq_file entries itself
Signature · 1 line
2.53.0