From: Greg KH <gregkh@linuxfoundation.org>
To: sunyiqi <sunyiqixm@gmail.com>
Cc: rafael@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpu: add CAP_SYSLOG check for reading crash_notes address
Date: Tue, 27 Aug 2024 11:15:25 +0200 [thread overview]
Message-ID: <2024082701-trailing-poster-6126@gregkh> (raw)
In-Reply-To: <20240827081133.872741-1-sunyiqixm@gmail.com>
On Tue, Aug 27, 2024 at 04:11:33PM +0800, sunyiqi wrote:
> CPU crash_notes value can be obtained through /sys/devices/system/cpu/\
> cpu[NUM]/crash_notes for leaking the phys address(introduced in kernel
> 5.10-rc1, but some distributions may migrate this feature to 4.x
> kernel).
> The relevant function is crash_notes_show() in file drivers/base/cpu.c.
>
> Though crash_notes file permission is 400 and owner is root:root,
> but in container, the root user can also read crash_notes which leads to
> information leak as most of kernel pointer value can not by read for
> root user in container without CAP_SYSLOG capability.
"most", but not all?
> In current linux kernel implementation, kernel pointer value or address
> printked by %pK is not directly exposed to root user in container. For
> kernel interface which includes those values, like /sys/kallsyms,
> /proc/net/packet, etc., address values are guarded by kernel function
> restricted_pointer(). Without CAP_SYSLOG capability, value 0 or NULL
> will be returned for reading those interfaces in container using root
> user.
I understand the request here, but why is giving the "real" kernel
pointer value somehow bad here? What can userspace in a container do
with it?
And why not give root permissions access to it container or not?
> In restricted_pointer() and container, address values only returned by
> kernel when root user has CAP_SYSLOG capability which is not the default
> capabilities for Docker container. CAP_SYSLOG prevents root user in
> container to get kernel pointer from lots of interfaces based on printk,
> but not for cpu crash_notes.
>
> Add CAP_SYSLOG permission check in crash_notes_show() for viewing kernel
> address.
Is this really the only place where this type of check needs to be
added?
> Fixes: aa838896d87a ("drivers core: Use sysfs_emit and sysfs_emit_at for show(device *...) functions")
> Signed-off-by: sunyiqi <sunyiqixm@gmail.com>
No cc: stable?
> ---
> drivers/base/cpu.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
> index fdaa24bb641a..a2f27bb0ffe6 100644
> --- a/drivers/base/cpu.c
> +++ b/drivers/base/cpu.c
> @@ -156,6 +156,9 @@ static ssize_t crash_notes_show(struct device *dev,
> unsigned long long addr;
> int cpunum;
>
> + if (!has_capability_noaudit(current, CAP_SYSLOG))
> + return sysfs_emit(buf, "%llx\n", 0ull);
Why not return an error? Why is 0 ok?
thanks,
greg k-h
next prev parent reply other threads:[~2024-08-27 9:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 8:11 [PATCH] cpu: add CAP_SYSLOG check for reading crash_notes address sunyiqi
2024-08-27 9:15 ` Greg KH [this message]
2024-08-28 2:31 ` sunyiqi
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=2024082701-trailing-poster-6126@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sunyiqixm@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox