@@ -13,6 +13,7 @@
#include <linux/binfmts.h>
#include <linux/sched/coredump.h>
#include <linux/sched/task.h>
+#include "../../lib/print-integer.h"
struct ctl_table_header;
struct mempolicy;
@@ -14,15 +14,19 @@ static const char *proc_self_get_link(struct dentry *dentry,
{
struct pid_namespace *ns = proc_pid_ns(inode);
pid_t tgid = task_tgid_nr_ns(current, ns);
+ char buf[10 + 1];
+ char *p = buf + sizeof(buf);
char *name;
if (!tgid)
return ERR_PTR(-ENOENT);
/* max length of unsigned int in decimal + NULL term */
- name = kmalloc(10 + 1, dentry ? GFP_KERNEL : GFP_ATOMIC);
+ name = kmalloc(sizeof(buf), dentry ? GFP_KERNEL : GFP_ATOMIC);
if (unlikely(!name))
return dentry ? ERR_PTR(-ENOMEM) : ERR_PTR(-ECHILD);
- sprintf(name, "%u", tgid);
+ *--p = '\0';
+ p = _print_integer_u32(p, tgid);
+ memcpy(name, p, buf + sizeof(buf) - p);
set_delayed_call(done, kfree_link, name);
return name;
}
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> --- fs/proc/internal.h | 1 + fs/proc/self.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-)