lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 6 Jun 2021 14:58:00 +0200
From:   Krzysztof WilczyƄski <kw@...ux.com>
To:     Amey Narkhede <ameynarkhede03@...il.com>
Cc:     Bjorn Helgaas <bhelgaas@...gle.com>, alex.williamson@...hat.com,
        Raphael Norwitz <raphael.norwitz@...anix.com>,
        linux-pci@...r.kernel.org, linux-kernel@...r.kernel.org,
        Shanker Donthineni <sdonthineni@...dia.com>,
        Sinan Kaya <okaya@...nel.org>
Subject: Re: [PATCH v5 4/7] PCI/sysfs: Allow userspace to query and set
 device reset mechanism

Hi Amey and Shanker,

[...]
> +static ssize_t reset_method_show(struct device *dev,
> +				 struct device_attribute *attr,
> +				 char *buf)
> +{
> +	struct pci_dev *pdev = to_pci_dev(dev);
> +	ssize_t len = 0;
> +	int i, prio;
> +
> +	for (prio = PCI_RESET_METHODS_NUM; prio; prio--) {
> +		for (i = 0; i < PCI_RESET_METHODS_NUM; i++) {
> +			if (prio == pdev->reset_methods[i]) {
> +				len += sysfs_emit_at(buf, len, "%s%s",
> +						     len ? "," : "",
> +						     pci_reset_fn_methods[i].name);
> +				break;
> +			}
> +		}
> +
> +		if (i == PCI_RESET_METHODS_NUM)
> +			break;
> +	}
> +
> +	return len;
> +}

Make sure to include trailing newline when exposing values through the
sysfs object to the userspace in the above show() function.

[...]
> +static ssize_t reset_method_store(struct device *dev,
> +				  struct device_attribute *attr,
> +				  const char *buf, size_t count)
[...]
> +
> +	while ((name = strsep((char **)&buf, ",")) != NULL) {
[...]

This is something that I wonder could benefit from the following:

  char *options, *end;

  if (count >= (PAGE_SIZE - 1))
	return -EINVAL;
  
  options = kstrndup(buf, count, GFP_KERNEL);
  if (!options)
  	return -ENOMEM;
  
  while ((name = strsep(&options, ",")) != NULL) {
  	...
  }
  
  ...
  
  kfree(options);

Why?  To avoid changing the string buffer that has been passed to
reset_method_store() as strsep() while parsing will update the content
of the buffer.  The cast to (char **), aside of most definitely allowing
to suppress the probable compiler warning, will also allow for what
should be a technically a constant string (to which we got a pointer to)
to be modified.  I am not sure how much could this be of a problem, but
I would try not to do it, if possible.

[...]
> +set_reset_methods:
> +	memcpy(pdev->reset_methods, reset_methods, sizeof(reset_methods));
> +	return count;
> +}
> +
> +static DEVICE_ATTR_RW(reset_method);

A small nitpikc: customary there is no space (a newline) between the
function and the macro, the macro follows immediately after.

	Krzysztof

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ