[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANpmjNN+Oq+U9V3v2hZ6g-BoLXhm-PS2Z0dU5NUCdD+CRuhO3A@mail.gmail.com>
Date: Tue, 1 Oct 2024 15:56:40 +0200
From: Marco Elver <elver@...gle.com>
To: ran xiaokai <ranxiaokai627@....com>
Cc: tglx@...utronix.de, dvyukov@...gle.com, kasan-dev@...glegroups.com,
linux-kernel@...r.kernel.org, Ran Xiaokai <ran.xiaokai@....com.cn>
Subject: Re: [PATCH 2/4] kcsan, debugfs: refactor set_report_filterlist_whitelist()
to return a value
On Wed, 25 Sept 2024 at 16:32, ran xiaokai <ranxiaokai627@....com> wrote:
>
> From: Ran Xiaokai <ran.xiaokai@....com.cn>
>
> This is a preparation patch, when converted to rcu lock,
> set_report_filterlist_whitelist() may fail due to memory alloction,
> refactor it to return a value, so the error codes can be
> passed to the userspace.
>
> Signed-off-by: Ran Xiaokai <ran.xiaokai@....com.cn>
> ---
> kernel/kcsan/debugfs.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/kcsan/debugfs.c b/kernel/kcsan/debugfs.c
> index ed483987869e..30547507f497 100644
> --- a/kernel/kcsan/debugfs.c
> +++ b/kernel/kcsan/debugfs.c
> @@ -131,13 +131,14 @@ bool kcsan_skip_report_debugfs(unsigned long func_addr)
> return ret;
> }
>
> -static void set_report_filterlist_whitelist(bool whitelist)
> +static ssize_t set_report_filterlist_whitelist(bool whitelist)
> {
> unsigned long flags;
>
> spin_lock_irqsave(&report_filterlist_lock, flags);
> report_filterlist.whitelist = whitelist;
> spin_unlock_irqrestore(&report_filterlist_lock, flags);
> + return 0;
> }
>
> /* Returns 0 on success, error-code otherwise. */
> @@ -225,6 +226,7 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
> char kbuf[KSYM_NAME_LEN];
> char *arg;
> const size_t read_len = min(count, sizeof(kbuf) - 1);
> + ssize_t ret;
This may be uninitialized depending on the branch taken below.
> if (copy_from_user(kbuf, buf, read_len))
> return -EFAULT;
> @@ -242,19 +244,19 @@ debugfs_write(struct file *file, const char __user *buf, size_t count, loff_t *o
> return -EINVAL;
> microbenchmark(iters);
> } else if (!strcmp(arg, "whitelist")) {
> - set_report_filterlist_whitelist(true);
> + ret = set_report_filterlist_whitelist(true);
> } else if (!strcmp(arg, "blacklist")) {
> - set_report_filterlist_whitelist(false);
> + ret = set_report_filterlist_whitelist(false);
> } else if (arg[0] == '!') {
> - ssize_t ret = insert_report_filterlist(&arg[1]);
> -
> - if (ret < 0)
> - return ret;
> + ret = insert_report_filterlist(&arg[1]);
> } else {
> return -EINVAL;
> }
>
> - return count;
> + if (ret < 0)
> + return ret;
> + else
> + return count;
> }
>
> static const struct file_operations debugfs_ops =
> --
> 2.15.2
>
Powered by blists - more mailing lists