* [PATCH v1 1/2] pinctrl: Duplicate user memory in one go in pinmux_select()
@ 2023-06-04 13:12 Andy Shevchenko
2023-06-04 13:12 ` [PATCH v1 2/2] pinctrl: Relax user input size " Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-06-04 13:12 UTC (permalink / raw)
To: Andy Shevchenko, linux-gpio, linux-kernel; +Cc: Linus Walleij
Current code is suboptimal in three ways:
1) it explicitly terminates the string which is not needed;
2) it might provoke additional faults, because asked lenght might be
bigger than the real one;
3) it consumes more than needed lines in the source.
Instead of using kmalloc() + strncpy_from_user() + terminating, just
utilize memdup_user_nul().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/pinctrl/pinmux.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 021382632608..2d2f3bd164d5 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -692,14 +692,9 @@ static ssize_t pinmux_select(struct file *file, const char __user *user_buf,
if (len > PINMUX_SELECT_MAX)
return -ENOMEM;
- buf = kzalloc(PINMUX_SELECT_MAX, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- ret = strncpy_from_user(buf, user_buf, PINMUX_SELECT_MAX);
- if (ret < 0)
- goto exit_free_buf;
- buf[len-1] = '\0';
+ buf = memdup_user_nul(user_buf, len);
+ if (IS_ERR(buf))
+ return PTR_ERR(buf);
/* remove leading and trailing spaces of input buffer */
gname = strstrip(buf);
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v1 2/2] pinctrl: Relax user input size in pinmux_select()
2023-06-04 13:12 [PATCH v1 1/2] pinctrl: Duplicate user memory in one go in pinmux_select() Andy Shevchenko
@ 2023-06-04 13:12 ` Andy Shevchenko
2023-06-09 7:22 ` Linus Walleij
[not found] ` <24d8898b-1e3b-8180-e96b-a3296de178a9@web.de>
2023-06-09 7:21 ` [PATCH v1 1/2] pinctrl: Duplicate user memory in one go " Linus Walleij
[not found] ` <39569326-6b1c-39b1-0eb2-f1c1d11251ec@web.de>
2 siblings, 2 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-06-04 13:12 UTC (permalink / raw)
To: Andy Shevchenko, linux-gpio, linux-kernel; +Cc: Linus Walleij
This is debugfs and there is no much sense to strict the user from
sending as much data as they can. The memdup_user_nul() will anyway
fail if there is not enough memory.
Relax the user input size by removing an artificial limitaion.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/pinctrl/pinmux.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 2d2f3bd164d5..82c750a31952 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -677,7 +677,6 @@ void pinmux_show_setting(struct seq_file *s,
DEFINE_SHOW_ATTRIBUTE(pinmux_functions);
DEFINE_SHOW_ATTRIBUTE(pinmux_pins);
-#define PINMUX_SELECT_MAX 128
static ssize_t pinmux_select(struct file *file, const char __user *user_buf,
size_t len, loff_t *ppos)
{
@@ -689,9 +688,6 @@ static ssize_t pinmux_select(struct file *file, const char __user *user_buf,
unsigned int num_groups;
int fsel, gsel, ret;
- if (len > PINMUX_SELECT_MAX)
- return -ENOMEM;
-
buf = memdup_user_nul(user_buf, len);
if (IS_ERR(buf))
return PTR_ERR(buf);
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v1 1/2] pinctrl: Duplicate user memory in one go in pinmux_select()
2023-06-04 13:12 [PATCH v1 1/2] pinctrl: Duplicate user memory in one go in pinmux_select() Andy Shevchenko
2023-06-04 13:12 ` [PATCH v1 2/2] pinctrl: Relax user input size " Andy Shevchenko
@ 2023-06-09 7:21 ` Linus Walleij
[not found] ` <39569326-6b1c-39b1-0eb2-f1c1d11251ec@web.de>
2 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-06-09 7:21 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel
On Sun, Jun 4, 2023 at 3:12 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Current code is suboptimal in three ways:
> 1) it explicitly terminates the string which is not needed;
> 2) it might provoke additional faults, because asked lenght might be
> bigger than the real one;
> 3) it consumes more than needed lines in the source.
>
> Instead of using kmalloc() + strncpy_from_user() + terminating, just
> utilize memdup_user_nul().
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Excellent patch, applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v1 2/2] pinctrl: Relax user input size in pinmux_select()
2023-06-04 13:12 ` [PATCH v1 2/2] pinctrl: Relax user input size " Andy Shevchenko
@ 2023-06-09 7:22 ` Linus Walleij
[not found] ` <24d8898b-1e3b-8180-e96b-a3296de178a9@web.de>
1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-06-09 7:22 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: linux-gpio, linux-kernel
On Sun, Jun 4, 2023 at 3:12 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> This is debugfs and there is no much sense to strict the user from
> sending as much data as they can. The memdup_user_nul() will anyway
> fail if there is not enough memory.
>
> Relax the user input size by removing an artificial limitaion.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Fair enough, patch applied!
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] pinctrl: Relax user input size in pinmux_select()
[not found] ` <24d8898b-1e3b-8180-e96b-a3296de178a9@web.de>
@ 2023-06-13 15:33 ` Andy Shevchenko
2023-06-13 18:17 ` Linus Walleij
1 sibling, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-06-13 15:33 UTC (permalink / raw)
To: Markus Elfring; +Cc: Linus Walleij, linux-gpio, kernel-janitors, LKML
On Tue, Jun 13, 2023 at 04:38:17PM +0200, Markus Elfring wrote:
> > This is debugfs and there is no much sense to strict the user from
> > sending as much data as they can. The memdup_user_nul() will anyway
> > fail if there is not enough memory.
> >
> > Relax the user input size by removing an artificial limitaion.
>
> How are the chances to avoid typos also in such a change description?
Almost 0. This is now part of the non-rebased branch. It can be fixed
if and only if
- something really wrong happened before this patch in the tree and has
to be fixed, and
- maintainer will remember to fix the typo.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] pinctrl: Duplicate user memory in one go in pinmux_select()
[not found] ` <39569326-6b1c-39b1-0eb2-f1c1d11251ec@web.de>
@ 2023-06-13 15:35 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-06-13 15:35 UTC (permalink / raw)
To: Markus Elfring; +Cc: Linus Walleij, linux-gpio, kernel-janitors, LKML
On Tue, Jun 13, 2023 at 04:30:44PM +0200, Markus Elfring wrote:
> > …, because asked lenght …
>
> * Are there any chances to avoid a typo in such a change description?
Not anymore as explained in the other email, but thanks for pointing this out.
> * Was a cover letter accidentally omitted?
What do you want to see in such cover letter? How can it be helpful?
(Note that these are rhetorical towards this change, as it's already
in the non-rebased branch)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] pinctrl: Relax user input size in pinmux_select()
[not found] ` <24d8898b-1e3b-8180-e96b-a3296de178a9@web.de>
2023-06-13 15:33 ` [PATCH " Andy Shevchenko
@ 2023-06-13 18:17 ` Linus Walleij
1 sibling, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-06-13 18:17 UTC (permalink / raw)
To: Markus Elfring; +Cc: Andy Shevchenko, linux-gpio, kernel-janitors, LKML
On Tue, Jun 13, 2023 at 4:38 PM Markus Elfring <Markus.Elfring@web.de> wrote:
> > This is debugfs and there is no much sense to strict the user from
> > sending as much data as they can. The memdup_user_nul() will anyway
> > fail if there is not enough memory.
> >
> > Relax the user input size by removing an artificial limitaion.
>
> How are the chances to avoid typos also in such a change description?
I don't care much about typos, and when a patch is coming from Andy
it's certainly not a blocker for anything since his patches are
of high technical value.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-06-13 18:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-04 13:12 [PATCH v1 1/2] pinctrl: Duplicate user memory in one go in pinmux_select() Andy Shevchenko
2023-06-04 13:12 ` [PATCH v1 2/2] pinctrl: Relax user input size " Andy Shevchenko
2023-06-09 7:22 ` Linus Walleij
[not found] ` <24d8898b-1e3b-8180-e96b-a3296de178a9@web.de>
2023-06-13 15:33 ` [PATCH " Andy Shevchenko
2023-06-13 18:17 ` Linus Walleij
2023-06-09 7:21 ` [PATCH v1 1/2] pinctrl: Duplicate user memory in one go " Linus Walleij
[not found] ` <39569326-6b1c-39b1-0eb2-f1c1d11251ec@web.de>
2023-06-13 15:35 ` [PATCH " Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).