lkml.org 
[lkml]   [2022]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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);
}

\
 
 \ /
  Last update: 2022-09-30 01:39    [W:1.501 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site