On Fri, Jul 24, 2020 at 10:22:36PM -0700, Pascal Bouchareine wrote: > This command attaches a description to a file descriptor for > troubleshooting purposes. The free string is displayed in the > process fdinfo file for that fd /proc/pid/fdinfo/fd. > > One intended usage is to allow processes to self-document sockets > for netstat and friends to report > +static long fcntl_set_description(struct file *file, char __user *desc) > +{ > + char *d; > + > + d = strndup_user(desc, MAX_FILE_DESC_SIZE); This should be kmem accounted because allocation is persistent. To make things more entertaining, strndup_user() doesn't have gfp_t argument. > + if (IS_ERR(d)) > + return PTR_ERR(d); > + > + spin_lock(&file->f_lock); > + kfree(file->f_description); > + file->f_description = d; > + spin_unlock(&file->f_lock); Generally kfree under spinlock is not good idea. You can replace the pointer and free without spinlock. > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -980,6 +980,9 @@ struct file { > struct address_space *f_mapping; > errseq_t f_wb_err; > errseq_t f_sb_err; /* for syncfs */ > + > +#define MAX_FILE_DESC_SIZE 256 > + char *f_description; struct file is nicely aligned to 256 bytes on distro configs. Will this break everything? $ cat /sys/kernel/slab/filp/object_size