From: sashiko-bot@kernel.org
To: "Cai Xinchen" <caixinchen1@huawei.com>
Cc: linux-security-module@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v3 6/8] lockdown: bound the status string with scnprintf
Date: Thu, 26 Nov 2026 12:52:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-235539@kernel.org> (raw)
In-Reply-To: <20261126131315.1256553-7-caixinchen1@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] lockdown: status string truncation in lockdown_read() on
concurrent write
--
commit 66eac39b9c466fbdeff2afcfbf4a18a53ab7e3f1
Author: Cai Xinchen <caixinchen1@huawei.com>
lockdown: bound the status string with scnprintf
This commit replaces sprintf() with scnprintf() in lockdown_read() and
sizes the status buffer to the exact length of the three level labels with
one bracketed active level.
> diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c
> index 84efd533fe5a6..239dbcdbabb40 100644
> --- a/security/lockdown/lockdown.c
> +++ b/security/lockdown/lockdown.c
> @@ -14,13 +14,28 @@
> #include <linux/lsm_hooks.h>
> #include <uapi/linux/lsm.h>
>
> +static const char lockdown_label_none[] = "none";
> +static const char lockdown_label_integrity[] = "integrity";
> +static const char lockdown_label_confidentiality[] = "confidentiality";
> +
> +/*
> + * The size of the lockdown status string: all three level labels
> + * with their trailing spaces, the brackets around the active one,
> + * and the terminating NUL. Whichever level is active, the string
> + * has the same length. The label sizeof() values include their
> + * own NULs, so only three more bytes are needed.
> + */
> +#define LOCKDOWN_STATUS_LEN (sizeof(lockdown_label_none) + \
> + sizeof(lockdown_label_integrity) + \
> + sizeof(lockdown_label_confidentiality) + 3)
[ ... ]
> @@ -134,7 +149,7 @@ static int __init lockdown_lsm_init(void)
> static ssize_t lockdown_read(struct file *filp, char __user *buf, size_t count,
> loff_t *ppos)
> {
> - char temp[80] = "";
> + char temp[LOCKDOWN_STATUS_LEN] = "";
> int i, offset = 0;
>
> for (i = 0; i < ARRAY_SIZE(lockdown_levels); i++) {
> @@ -144,9 +159,13 @@ static ssize_t lockdown_read(struct file *filp, char __user *buf, size_t count,
> const char *label = lockdown_reasons[level];
>
> if (kernel_locked_down == level)
> - offset += sprintf(temp+offset, "[%s] ", label);
> + offset += scnprintf(temp + offset,
> + sizeof(temp) - offset,
> + "[%s] ", label);
> else
> - offset += sprintf(temp+offset, "%s ", label);
> + offset += scnprintf(temp + offset,
> + sizeof(temp) - offset,
> + "%s ", label);
> }
> }
[Severity: Low]
Can a concurrent lockdown_write() cause lockdown_read() to truncate the
status string in temp[]?
LOCKDOWN_STATUS_LEN (34 bytes) only leaves room for one pair of brackets,
and kernel_locked_down is re-read on each iteration of the loop:
CPU0 CPU1
lockdown_read()
i = 0 (LOCKDOWN_NONE):
kernel_locked_down == level
scnprintf(..., "[none] ")
lockdown_write()
lock_kernel_down(...,
LOCKDOWN_INTEGRITY_MAX)
i = 1 (LOCKDOWN_INTEGRITY_MAX):
kernel_locked_down == level
scnprintf(..., "[integrity] ")
i = 2 (LOCKDOWN_CONFIDENTIALITY_MAX):
scnprintf(..., "confidentiality ")
<-- truncated to "confidentialit"
temp[offset - 1] = '\n' then overwrites the last character of the label,
returning "[none] [integrity] confidentiali\n" to userspace. Reading
kernel_locked_down once with READ_ONCE() before the loop would avoid
matching more than one level.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126131315.1256553-1-caixinchen1@huawei.com?part=6
next prev parent reply other threads:[~2026-11-26 12:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 13:13 [PATCH v3 0/8] lockdown: fix the securityfs interface and add tests Cai Xinchen
2026-11-26 12:55 ` sashiko-bot
2026-11-26 13:13 ` [PATCH v3 1/8] lockdown: Add break in lockdown_write Cai Xinchen
2026-11-26 13:13 ` [PATCH v3 2/8] lockdown: remove useless decrement operation Cai Xinchen
2026-11-26 13:13 ` [PATCH v3 3/8] lockdown: select SECURITYFS Cai Xinchen
2026-11-26 13:13 ` [PATCH v3 4/8] lsm: remove unused lockdown audit data Cai Xinchen
2026-11-26 13:13 ` [PATCH v3 5/8] lockdown: drop an unused include and move lockdown_reasons Cai Xinchen
2026-11-26 13:13 ` [PATCH v3 6/8] lockdown: bound the status string with scnprintf Cai Xinchen
2026-11-26 12:52 ` sashiko-bot [this message]
2026-11-26 13:13 ` [PATCH v3 7/8] Documentation/ABI: document the lockdown securityfs file Cai Xinchen
2026-11-26 13:13 ` [PATCH v3 8/8] selftests/lsm: add lockdown securityfs test Cai Xinchen
2026-11-26 12:55 ` sashiko-bot
2026-11-27 2:10 ` Guicai Ma
2026-11-30 7:19 ` Cai Xinchen
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=sashiko-outbox-235539@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=caixinchen1@huawei.com \
--cc=linux-security-module@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.