All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Stuart Yoder <stuyoder@gmail.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Vineeth Vijayan <vneethv@linux.ibm.com>,
	Peter Oberparleiter <oberpar@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Andy Gross <agross@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-clk <linux-clk@vger.kernel.org>,
	NXP Linux Team <linux-imx@nxp.com>,
	linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
	Linux on Hyper-V List <linux-hyperv@vger.kernel.org>,
	linux-pci <linux-pci@vger.kernel.org>,
	linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-arm-msm@vger.kernel.org,
	ALSA Development Mailing List <alsa-devel@alsa-project.org>,
	linux-spi <linux-spi@vger.kernel.org>,
	virtualization@lists.linux-foundation.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: Re: [PATCH v5 01/11] driver: platform: Add helper for safer setting of driver_override
Date: Sun, 3 Apr 2022 20:26:51 +0200	[thread overview]
Message-ID: <fb2b05f0-7609-1fa7-4d69-c64e082e2e2b@linaro.org> (raw)
In-Reply-To: <CAHp75VeaQdzUKJSKzH9FjbmON5asqH799AS8OzHGoDiRnJifNw@mail.gmail.com>

On 16/03/2022 16:54, Andy Shevchenko wrote:
> On Wed, Mar 16, 2022 at 5:06 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@canonical.com> wrote:
> 
> ...
> 
>> +int driver_set_override(struct device *dev, const char **override,
>> +                       const char *s, size_t len)
>> +{
>> +       const char *new, *old;
>> +       char *cp;

I focused on some other topics, so I did not respond to your questions
for some time.

> 
>> +       if (!dev || !override || !s)
>> +               return -EINVAL;
> 
> Sorry, I didn't pay much attention on this. First of all, I would drop
> dev checks and simply require that dev should be valid. Do you expect
> this can be called when dev is invalid?

No, I can skip the check.

> I would like to hear if it's
> anything but theoretical. Second one, is the !s requirement. Do I
> understand correctly that the string must be always present? But then
> how we NULify the override? Is it possible?

I did not change the convention of this sysfs hook, so removing of
override is passing empty string "". Have in mind that his interface is
mainly for sysfs, not for other drivers.

> Third one is absence of
> len check. See below.
> 
>> +       /*
>> +        * The stored value will be used in sysfs show callback (sysfs_emit()),
>> +        * which has a length limit of PAGE_SIZE and adds a trailing newline.
>> +        * Thus we can store one character less to avoid truncation during sysfs
>> +        * show.
>> +        */
>> +       if (len >= (PAGE_SIZE - 1))
>> +               return -EINVAL;
> 
> I would relax this to make sure we can use it if \n is within this limit.

Relax in what way? Store more than PAGE_SIZE? This is a user-visible
string and the name of a driver.

> 
>> +       cp = strnchr(s, len, '\n');
>> +       if (cp)
>> +               len = cp - s;
>> +
>> +       new = kstrndup(s, len, GFP_KERNEL);
> 
> Here is a word about the len check.
> 
>> +       if (!new)
> 
> If len == 0, this won't trigger and you have something very
> interesting as a result.

True, empty string would be set as override. The API says that empty
string clears the override, so len==0 should be valid (just like "\n" is
ok).

> 
> One way is to use ZERO_PTR_OR_NULL() another is explicitly check for 0
> and issue a (different?) error code.



Best regards,
Krzysztof

WARNING: multiple messages have this Message-ID (diff)
From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Stuart Yoder <stuyoder@gmail.com>,
	"K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Vineeth Vijayan <vneethv@linux.ibm.com>,
	Peter Oberparleiter <oberpar@linux.ibm.com>,
	Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Andy Gross <agross@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-clk <linux-clk@vger.kernel.org>,
	NXP Linux Team <linux-imx@nxp.com>,
	linux-arm Mailing List <linux-arm-kernel@lists.infradead.org>,
	Linux on Hyper-V List <linux-hyperv@vger.kernel.org>,
	linux-pci <linux-pci@vger.kernel.org>,
	linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org,
	linux-arm-msm@vger.kernel.org,
	ALSA Development Mailing List <alsa-devel@alsa-project.org>,
	linux-spi <linux-spi@vger.kernel.org>,
	virtualization@lists.linux-foundation.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: Re: [PATCH v5 01/11] driver: platform: Add helper for safer setting of driver_override
Date: Sun, 3 Apr 2022 20:26:51 +0200	[thread overview]
Message-ID: <fb2b05f0-7609-1fa7-4d69-c64e082e2e2b@linaro.org> (raw)
In-Reply-To: <CAHp75VeaQdzUKJSKzH9FjbmON5asqH799AS8OzHGoDiRnJifNw@mail.gmail.com>

On 16/03/2022 16:54, Andy Shevchenko wrote:
> On Wed, Mar 16, 2022 at 5:06 PM Krzysztof Kozlowski
> <krzysztof.kozlowski@canonical.com> wrote:
> 
> ...
> 
>> +int driver_set_override(struct device *dev, const char **override,
>> +                       const char *s, size_t len)
>> +{
>> +       const char *new, *old;
>> +       char *cp;

I focused on some other topics, so I did not respond to your questions
for some time.

> 
>> +       if (!dev || !override || !s)
>> +               return -EINVAL;
> 
> Sorry, I didn't pay much attention on this. First of all, I would drop
> dev checks and simply require that dev should be valid. Do you expect
> this can be called when dev is invalid?

No, I can skip the check.

> I would like to hear if it's
> anything but theoretical. Second one, is the !s requirement. Do I
> understand correctly that the string must be always present? But then
> how we NULify the override? Is it possible?

I did not change the convention of this sysfs hook, so removing of
override is passing empty string "". Have in mind that his interface is
mainly for sysfs, not for other drivers.

> Third one is absence of
> len check. See below.
> 
>> +       /*
>> +        * The stored value will be used in sysfs show callback (sysfs_emit()),
>> +        * which has a length limit of PAGE_SIZE and adds a trailing newline.
>> +        * Thus we can store one character less to avoid truncation during sysfs
>> +        * show.
>> +        */
>> +       if (len >= (PAGE_SIZE - 1))
>> +               return -EINVAL;
> 
> I would relax this to make sure we can use it if \n is within this limit.

Relax in what way? Store more than PAGE_SIZE? This is a user-visible
string and the name of a driver.

> 
>> +       cp = strnchr(s, len, '\n');
>> +       if (cp)
>> +               len = cp - s;
>> +
>> +       new = kstrndup(s, len, GFP_KERNEL);
> 
> Here is a word about the len check.
> 
>> +       if (!new)
> 
> If len == 0, this won't trigger and you have something very
> interesting as a result.

True, empty string would be set as override. The API says that empty
string clears the override, so len==0 should be valid (just like "\n" is
ok).

> 
> One way is to use ZERO_PTR_OR_NULL() another is explicitly check for 0
> and issue a (different?) error code.



Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-04-03 18:27 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 15:05 [PATCH v5 00/11] Fix broken usage of driver_override (and kfree of static memory) Krzysztof Kozlowski
2022-03-16 15:05 ` Krzysztof Kozlowski
2022-03-16 15:05 ` Krzysztof Kozlowski
2022-03-16 15:05 ` [PATCH v5 01/11] driver: platform: Add helper for safer setting of driver_override Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:54   ` Andy Shevchenko
2022-03-16 15:54     ` Andy Shevchenko
2022-03-16 15:54     ` Andy Shevchenko
2022-03-16 15:54     ` Andy Shevchenko
2022-04-03 18:26     ` Krzysztof Kozlowski [this message]
2022-04-03 18:26       ` Krzysztof Kozlowski
2022-03-16 15:05 ` [PATCH v5 02/11] amba: Use driver_set_override() instead of open-coding Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05 ` [PATCH v5 03/11] fsl-mc: " Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05 ` [PATCH v5 04/11] hv: " Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05 ` [PATCH v5 05/11] PCI: " Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05 ` [PATCH v5 06/11] s390/cio: " Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:05   ` Krzysztof Kozlowski
2022-03-16 15:07 ` [PATCH v5 07/11] spi: Use helper for safer setting of driver_override Krzysztof Kozlowski
2022-03-16 15:07   ` Krzysztof Kozlowski
2022-03-16 15:07   ` Krzysztof Kozlowski
2022-03-16 15:08 ` [PATCH v5 08/11] vdpa: " Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08 ` [PATCH v5 09/11] clk: imx: scu: Fix kfree() of static memory on setting driver_override Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08 ` [PATCH v5 10/11] slimbus: qcom-ngd: " Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08 ` [PATCH v5 11/11] rpmsg: " Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 15:08   ` Krzysztof Kozlowski
2022-03-16 19:38   ` Krzysztof Kozlowski
2022-03-16 19:38     ` Krzysztof Kozlowski
2022-03-16 19:38     ` Krzysztof Kozlowski
2022-03-16 23:35   ` kernel test robot

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=fb2b05f0-7609-1fa7-4d69-c64e082e2e2b@linaro.org \
    --to=krzysztof.kozlowski@linaro.org \
    --cc=agordeev@linux.ibm.com \
    --cc=agross@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=decui@microsoft.com \
    --cc=gor@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=haiyangz@microsoft.com \
    --cc=hca@linux.ibm.com \
    --cc=krzysztof.kozlowski@canonical.com \
    --cc=kys@microsoft.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mathieu.poirier@linaro.org \
    --cc=oberpar@linux.ibm.com \
    --cc=rafael@kernel.org \
    --cc=sthemmin@microsoft.com \
    --cc=stuyoder@gmail.com \
    --cc=svens@linux.ibm.com \
    --cc=torvalds@linux-foundation.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=vneethv@linux.ibm.com \
    --cc=wei.liu@kernel.org \
    /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.