[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241016085102.GW17263@noisy.programming.kicks-ass.net>
Date: Wed, 16 Oct 2024 10:51:02 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Lucas De Marchi <lucas.demarchi@...el.com>
Cc: linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Umesh Nerlige Ramappa <umesh.nerlige.ramappa@...el.com>,
Ian Rogers <irogers@...gle.com>,
Tvrtko Ursulin <tvrtko.ursulin@...lia.com>
Subject: Re: [PATCH 1/5] perf: Add dummy pmu module
On Tue, Oct 08, 2024 at 01:34:57PM -0500, Lucas De Marchi wrote:
> +static int parse_device(const char __user *ubuf, size_t size, u32 *instance)
> +{
> + char buf[16];
> + ssize_t len;
> +
> + if (size > sizeof(buf) - 1)
> + return -E2BIG;
> +
> + len = strncpy_from_user(buf, ubuf, sizeof(buf));
> + if (len < 0 || len >= sizeof(buf) - 1)
> + return -E2BIG;
> +
> + if (kstrtou32(buf, 0, instance))
> + return -EINVAL;
> +
> + return size;
> +}
I had to change this to:
+static int parse_device(const char __user *ubuf, size_t size, u32 *instance)
+{
+ int ret = kstrtouint_from_user(ubuf, size, 0, instance);
+ if (ret) {
+ printk("suckage: %d\n", ret);
+ return ret;
+ }
+ return size;
+}
because otherwise it didn't want to work for me; I kept getting garbage
at the end and things failing. Specifically, it looked like the string
presented by userspace was not '\0' terminated, ubuf was pointing to
"1...garbage..." and size was 1.
Powered by blists - more mailing lists