Re: [PATCH 1/5] perf: Add dummy pmu module

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 16, 2024 at 10:51:02AM +0200, Peter Zijlstra wrote:
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.

oh... it's the sysfs (that PCI drivers use) that is guaranteed to be
nul-terminated. debugfs is not. And it probably worked for me because of
CONFIG_INIT_STACK_ALL_ZERO=y that comes from my distro.

and this version is also shorter and simpler.

thanks
Lucas De Marchi



[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux