All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Pascal Bouchareine <kalou@tfz.net>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-api@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	Jeff Layton <jlayton@poochiereds.net>,
	"J. Bruce Fields" <bfields@fieldses.org>
Subject: Re: [PATCH v3] proc,fcntl: introduce F_SET_DESCRIPTION
Date: Mon, 27 Jul 2020 17:21:40 +0300	[thread overview]
Message-ID: <20200727142140.GA116567@localhost.localdomain> (raw)
In-Reply-To: <20200725052236.4062-1-kalou@tfz.net>

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

  reply	other threads:[~2020-07-27 14:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-25  0:40 [PATCH] proc,fcntl: introduce F_SET_DESCRIPTION Pascal Bouchareine
2020-07-25  4:59 ` [PATCH v2] " Pascal Bouchareine
2020-07-25  5:15   ` [PATCH v3] 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 Pascal Bouchareine
2020-07-26  2:11     ` Pascal Bouchareine
2020-07-25  5:22   ` [PATCH v3] proc,fcntl: introduce F_SET_DESCRIPTION Pascal Bouchareine
2020-07-27 14:21     ` Alexey Dobriyan [this message]
2020-07-28  1:39       ` Pascal Bouchareine
2020-07-28  6:25         ` Pascal Bouchareine
2020-07-25 22:10 ` [PATCH] " Al Viro
2020-07-26  1:42   ` Pascal Bouchareine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200727142140.GA116567@localhost.localdomain \
    --to=adobriyan@gmail.com \
    --cc=bfields@fieldses.org \
    --cc=jlayton@poochiereds.net \
    --cc=kalou@tfz.net \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.