lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 30 Sep 2022 00:38:08 +0100
From:   Al Viro <viro@...iv.linux.org.uk>
To:     "Eric W. Biederman" <ebiederm@...ssion.com>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        David Laight <David.Laight@...lab.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        "Serge E. Hallyn" <serge@...lyn.com>
Subject: Re: [CFT][PATCH] proc: Update /proc/net to point at the accessing
 threads network namespace

On Thu, Sep 29, 2022 at 05:48:29PM -0500, Eric W. Biederman wrote:

> +static const char *proc_net_symlink_get_link(struct dentry *dentry,
> +					     struct inode *inode,
> +					     struct delayed_call *done)
> +{
> +	struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
> +	pid_t tid = task_pid_nr_ns(current, ns);
> +	char *name;
> +
> +	if (!tid)
> +		return ERR_PTR(-ENOENT);
> +	name = kmalloc(10 + 4 + 1, dentry ? GFP_KERNEL : GFP_ATOMIC);
> +	if (unlikely(!name))
> +		return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD);
> +	sprintf(name, "%u/net", tid);
> +	set_delayed_call(done, kfree_link, name);
> +	return name;
> +}

Just to troll adobriyan a bit:

static const char *dynamic_get_link(struct delayed_call *done,
				    bool is_rcu,
				    const char *fmt, ...)
{
	va_list args;
	char *body;

	va_start(args, fmt);
	body = kvasprintf(is_rcu ? GFP_ATOMIC : GFP_KERNEL, fmt, args);
	va_end(args);

	if (unlikely(!body))
		return is_rcu ? ERR_PTR(-ECHILD) : ERR_PTR(-ENOMEM);
	set_delayed_call(done, kfree_link, body);
	return body;
}

static const char *proc_net_symlink_get_link(struct dentry *dentry,
					     struct inode *inode,
					     struct delayed_call *done)
{
	struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
	pid_t tid = task_pid_nr_ns(current, ns);

	if (!tid)
		return ERR_PTR(-ENOENT);
	return dyname_get_link(done, !dentry, "%u/net", tid);
}

static const char *proc_self_get_link(struct dentry *dentry,
				      struct inode *inode,
				      struct delayed_call *done)
{
	struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
	pid_t tgid = task_tgid_nr_ns(current, ns);

	if (!tgid)
		return ERR_PTR(-ENOENT);
	return dynamic_get_link(done, !dentry, "%u", tgid);
}

static const char *proc_thread_self_get_link(struct dentry *dentry,
					     struct inode *inode,
					     struct delayed_call *done)
{
	struct pid_namespace *ns = proc_pid_ns(inode->i_sb);
	pid_t tgid = task_tgid_nr_ns(current, ns);
	pid_t pid = task_pid_nr_ns(current, ns);

	if (!pid)
		return ERR_PTR(-ENOENT);
	return dynamic_get_link(done, !dentry, "%u/task/%u", tgid, pid);
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ