mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
keys: translate request_key_auth pid for the reading procfs instance
request_key_auth_describe() prints rka->pid into /proc/keys as a raw pid_t in the initial pid namespace. A reader can open /proc/keys through a mount in another pid namespace. That reader sees a number with no meaning there. The number can even name an unrelated task. The line needs VIEW on the key. So the reader either shares the key owner's uid or possesses the key. The fix keeps a struct pid. Commit4f82f45730("net ip6 flowlabel: Make owner a union of struct pid * and kuid_t") gave /proc/net/ip6_flowlabel the same storage. The print goes through pid_nr_ns(). It renders against the pid namespace of the procfs instance the line is read through. Commitad08978ab4("ipv6/flowlabel: simplify pid namespace lookup") moved that print to the same anchor. Output through an initial namespace /proc does not change. The line shows 0 for a requestor with no number in that namespace. Translating at read time was the alternative. find_pid_ns() can resolve a recycled number. The line would then name a live task with no connection to the key. A stored struct pid gives 0 instead when the requestor has no number there. Link: https://lore.kernel.org/keyrings/20260809110202.2180410-1-maoyixie.tju@gmail.com/ Fixes:78b7280cce("KEYS: Improve /proc/keys") Cc: stable@vger.kernel.org # v5.10+ Assisted-by: Claude:claude-opus-5 codeql Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com> Link: https://lore.kernel.org/r/20260821095935.1864998-1-maoyixie.tju@gmail.com Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
This commit is contained in:
parent
2725ab3f5a
commit
0d6a4268b0
|
|
@ -22,7 +22,7 @@ struct request_key_auth {
|
|||
const struct cred *cred;
|
||||
void *callout_info;
|
||||
size_t callout_len;
|
||||
pid_t pid;
|
||||
struct pid *pid;
|
||||
char op[8];
|
||||
} __randomize_layout;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include <linux/sched.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/pid.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/uaccess.h>
|
||||
|
|
@ -73,7 +75,10 @@ static void request_key_auth_describe(const struct key *key,
|
|||
seq_puts(m, "key:");
|
||||
seq_puts(m, key->description);
|
||||
if (key_is_positive(key))
|
||||
seq_printf(m, " pid:%d ci:%zu", rka->pid, rka->callout_len);
|
||||
seq_printf(m, " pid:%d ci:%zu",
|
||||
pid_nr_ns(rka->pid,
|
||||
proc_pid_ns(file_inode(m->file)->i_sb)),
|
||||
rka->callout_len);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -113,6 +118,7 @@ static void free_request_key_auth(struct request_key_auth *rka)
|
|||
if (rka->cred)
|
||||
put_cred(rka->cred);
|
||||
kfree(rka->callout_info);
|
||||
put_pid(rka->pid);
|
||||
kfree(rka);
|
||||
}
|
||||
|
||||
|
|
@ -226,14 +232,14 @@ struct key *request_key_auth_new(struct key *target, const char *op,
|
|||
|
||||
irka = cred->request_key_auth->payload.data[0];
|
||||
rka->cred = get_cred(irka->cred);
|
||||
rka->pid = irka->pid;
|
||||
rka->pid = get_pid(irka->pid);
|
||||
|
||||
up_read(&cred->request_key_auth->sem);
|
||||
}
|
||||
else {
|
||||
/* it isn't - use this process as the context */
|
||||
rka->cred = get_cred(cred);
|
||||
rka->pid = current->pid;
|
||||
rka->pid = get_pid(task_pid(current));
|
||||
}
|
||||
|
||||
rka->target_key = key_get(target);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user