* [PATCH 0/4] ARM: amba: driver_override improvements
@ 2018-01-19 15:24 Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 1/4] ARM: amba: Make driver_override output consistent with other buses Geert Uytterhoeven
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2018-01-19 15:24 UTC (permalink / raw)
To: Russell King
Cc: Antonios Motakis, Adrian Salido, Sasha Levin, Greg Kroah-Hartman,
linux-kernel, Geert Uytterhoeven
Hi Russell,
This patch series contains improvements to driver_override handling in
the AMBA bus driver, including two bugfixes that are based on similar
fixes for the PCI and platform buses.
Thanks!
Geert Uytterhoeven (4):
ARM: amba: Make driver_override output consistent with other buses
ARM: amba: Fix race condition with driver_override
ARM: amba: Don't read past the end of sysfs "driver_override" buffer
ARM: amba: Fix wrong indentation in driver_override_store()
drivers/amba/bus.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
--
2.7.4
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] ARM: amba: Make driver_override output consistent with other buses
2018-01-19 15:24 [PATCH 0/4] ARM: amba: driver_override improvements Geert Uytterhoeven
@ 2018-01-19 15:24 ` Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 2/4] ARM: amba: Fix race condition with driver_override Geert Uytterhoeven
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2018-01-19 15:24 UTC (permalink / raw)
To: Russell King
Cc: Antonios Motakis, Adrian Salido, Sasha Levin, Greg Kroah-Hartman,
linux-kernel, Geert Uytterhoeven
For AMBA devices with unconfigured driver override, the
"driver_override" sysfs virtual file is empty, while it contains
"(null)" for platform and PCI devices.
Make AMBA consistent with other buses by dropping the test for a NULL
pointer.
Note that contrary to popular belief, sprintf() handles NULL pointers
fine; they are printed as "(null)".
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/amba/bus.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 594c228d2f021123..6ffd778352e6d953 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -70,9 +70,6 @@ static ssize_t driver_override_show(struct device *_dev,
{
struct amba_device *dev = to_amba_device(_dev);
- if (!dev->driver_override)
- return 0;
-
return sprintf(buf, "%s\n", dev->driver_override);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] ARM: amba: Fix race condition with driver_override
2018-01-19 15:24 [PATCH 0/4] ARM: amba: driver_override improvements Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 1/4] ARM: amba: Make driver_override output consistent with other buses Geert Uytterhoeven
@ 2018-01-19 15:24 ` Geert Uytterhoeven
2018-03-02 18:23 ` Todd Kjos
2018-01-19 15:24 ` [PATCH 3/4] ARM: amba: Don't read past the end of sysfs "driver_override" buffer Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 4/4] ARM: amba: Fix wrong indentation in driver_override_store() Geert Uytterhoeven
3 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2018-01-19 15:24 UTC (permalink / raw)
To: Russell King
Cc: Antonios Motakis, Adrian Salido, Sasha Levin, Greg Kroah-Hartman,
linux-kernel, Geert Uytterhoeven
The driver_override implementation is susceptible to a race condition
when different threads are reading vs storing a different driver
override. Add locking to avoid this race condition.
Cfr. commits 6265539776a0810b ("driver core: platform: fix race
condition with driver_override") and 9561475db680f714 ("PCI: Fix race
condition with driver_override").
Fixes: 3cf385713460eb2b ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/amba/bus.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 6ffd778352e6d953..36c5653ced5742b7 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -69,8 +69,12 @@ static ssize_t driver_override_show(struct device *_dev,
struct device_attribute *attr, char *buf)
{
struct amba_device *dev = to_amba_device(_dev);
+ ssize_t len;
- return sprintf(buf, "%s\n", dev->driver_override);
+ device_lock(_dev);
+ len = sprintf(buf, "%s\n", dev->driver_override);
+ device_unlock(_dev);
+ return len;
}
static ssize_t driver_override_store(struct device *_dev,
@@ -78,7 +82,7 @@ static ssize_t driver_override_store(struct device *_dev,
const char *buf, size_t count)
{
struct amba_device *dev = to_amba_device(_dev);
- char *driver_override, *old = dev->driver_override, *cp;
+ char *driver_override, *old, *cp;
if (count > PATH_MAX)
return -EINVAL;
@@ -91,12 +95,15 @@ static ssize_t driver_override_store(struct device *_dev,
if (cp)
*cp = '\0';
+ device_lock(_dev);
+ old = dev->driver_override;
if (strlen(driver_override)) {
dev->driver_override = driver_override;
} else {
kfree(driver_override);
dev->driver_override = NULL;
}
+ device_unlock(_dev);
kfree(old);
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] ARM: amba: Don't read past the end of sysfs "driver_override" buffer
2018-01-19 15:24 [PATCH 0/4] ARM: amba: driver_override improvements Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 1/4] ARM: amba: Make driver_override output consistent with other buses Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 2/4] ARM: amba: Fix race condition with driver_override Geert Uytterhoeven
@ 2018-01-19 15:24 ` Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 4/4] ARM: amba: Fix wrong indentation in driver_override_store() Geert Uytterhoeven
3 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2018-01-19 15:24 UTC (permalink / raw)
To: Russell King
Cc: Antonios Motakis, Adrian Salido, Sasha Levin, Greg Kroah-Hartman,
linux-kernel, Geert Uytterhoeven
When printing the driver_override parameter when it is 4095 and 4094
bytes long, the printing code would access invalid memory because we
need count + 1 bytes for printing.
Cfr. commits 4efe874aace57dba ("PCI: Don't read past the end of sysfs
"driver_override" buffer") and bf563b01c2895a4b ("driver core: platform:
Don't read past the end of "driver_override" buffer").
Fixes: 3cf385713460eb2b ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/amba/bus.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 36c5653ced5742b7..4a3ac31c07d0ee49 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -84,7 +84,8 @@ static ssize_t driver_override_store(struct device *_dev,
struct amba_device *dev = to_amba_device(_dev);
char *driver_override, *old, *cp;
- if (count > PATH_MAX)
+ /* We need to keep extra room for a newline */
+ if (count >= (PAGE_SIZE - 1))
return -EINVAL;
driver_override = kstrndup(buf, count, GFP_KERNEL);
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] ARM: amba: Fix wrong indentation in driver_override_store()
2018-01-19 15:24 [PATCH 0/4] ARM: amba: driver_override improvements Geert Uytterhoeven
` (2 preceding siblings ...)
2018-01-19 15:24 ` [PATCH 3/4] ARM: amba: Don't read past the end of sysfs "driver_override" buffer Geert Uytterhoeven
@ 2018-01-19 15:24 ` Geert Uytterhoeven
3 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2018-01-19 15:24 UTC (permalink / raw)
To: Russell King
Cc: Antonios Motakis, Adrian Salido, Sasha Levin, Greg Kroah-Hartman,
linux-kernel, Geert Uytterhoeven
Indentation is one TAB and 7 spaces instead of 2 TABs.
Fixes: 3cf385713460eb2b ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/amba/bus.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 4a3ac31c07d0ee49..842314a439fdd4eb 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -101,8 +101,8 @@ static ssize_t driver_override_store(struct device *_dev,
if (strlen(driver_override)) {
dev->driver_override = driver_override;
} else {
- kfree(driver_override);
- dev->driver_override = NULL;
+ kfree(driver_override);
+ dev->driver_override = NULL;
}
device_unlock(_dev);
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] ARM: amba: Fix race condition with driver_override
2018-01-19 15:24 ` [PATCH 2/4] ARM: amba: Fix race condition with driver_override Geert Uytterhoeven
@ 2018-03-02 18:23 ` Todd Kjos
2018-03-05 8:08 ` Geert Uytterhoeven
0 siblings, 1 reply; 7+ messages in thread
From: Todd Kjos @ 2018-03-02 18:23 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Russell King, Antonios Motakis, Adrian Salido, Sasha Levin,
Greg Kroah-Hartman, LKML, stable
+stable
what is the status of this patch? We'd like to get it into the android
common branches to fix possible double free.
On Fri, Jan 19, 2018 at 7:24 AM, Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> The driver_override implementation is susceptible to a race condition
> when different threads are reading vs storing a different driver
> override. Add locking to avoid this race condition.
>
> Cfr. commits 6265539776a0810b ("driver core: platform: fix race
> condition with driver_override") and 9561475db680f714 ("PCI: Fix race
> condition with driver_override").
>
> Fixes: 3cf385713460eb2b ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> drivers/amba/bus.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 6ffd778352e6d953..36c5653ced5742b7 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -69,8 +69,12 @@ static ssize_t driver_override_show(struct device *_dev,
> struct device_attribute *attr, char *buf)
> {
> struct amba_device *dev = to_amba_device(_dev);
> + ssize_t len;
>
> - return sprintf(buf, "%s\n", dev->driver_override);
> + device_lock(_dev);
> + len = sprintf(buf, "%s\n", dev->driver_override);
> + device_unlock(_dev);
> + return len;
> }
>
> static ssize_t driver_override_store(struct device *_dev,
> @@ -78,7 +82,7 @@ static ssize_t driver_override_store(struct device *_dev,
> const char *buf, size_t count)
> {
> struct amba_device *dev = to_amba_device(_dev);
> - char *driver_override, *old = dev->driver_override, *cp;
> + char *driver_override, *old, *cp;
>
> if (count > PATH_MAX)
> return -EINVAL;
> @@ -91,12 +95,15 @@ static ssize_t driver_override_store(struct device *_dev,
> if (cp)
> *cp = '\0';
>
> + device_lock(_dev);
> + old = dev->driver_override;
> if (strlen(driver_override)) {
> dev->driver_override = driver_override;
> } else {
> kfree(driver_override);
> dev->driver_override = NULL;
> }
> + device_unlock(_dev);
>
> kfree(old);
>
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] ARM: amba: Fix race condition with driver_override
2018-03-02 18:23 ` Todd Kjos
@ 2018-03-05 8:08 ` Geert Uytterhoeven
0 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2018-03-05 8:08 UTC (permalink / raw)
To: Todd Kjos
Cc: Geert Uytterhoeven, Russell King, Antonios Motakis,
Adrian Salido, Sasha Levin, Greg Kroah-Hartman, LKML, stable
Hi Todd,
On Fri, Mar 2, 2018 at 7:23 PM, Todd Kjos <tkjos@android.com> wrote:
> +stable
>
> what is the status of this patch? We'd like to get it into the android
> common branches to fix possible double free.
Thanks for your interest!
So far this patch (and the 3 others in the series) haven't received any
comments. If someone sends a Acked-by or Reviewed-by, I can submit them
to RMK's patch system.
Thanks!
> On Fri, Jan 19, 2018 at 7:24 AM, Geert Uytterhoeven
> <geert+renesas@glider.be> wrote:
>> The driver_override implementation is susceptible to a race condition
>> when different threads are reading vs storing a different driver
>> override. Add locking to avoid this race condition.
>>
>> Cfr. commits 6265539776a0810b ("driver core: platform: fix race
>> condition with driver_override") and 9561475db680f714 ("PCI: Fix race
>> condition with driver_override").
>>
>> Fixes: 3cf385713460eb2b ("ARM: 8256/1: driver coamba: add device binding path 'driver_override'")
>> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-03-05 8:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-19 15:24 [PATCH 0/4] ARM: amba: driver_override improvements Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 1/4] ARM: amba: Make driver_override output consistent with other buses Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 2/4] ARM: amba: Fix race condition with driver_override Geert Uytterhoeven
2018-03-02 18:23 ` Todd Kjos
2018-03-05 8:08 ` Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 3/4] ARM: amba: Don't read past the end of sysfs "driver_override" buffer Geert Uytterhoeven
2018-01-19 15:24 ` [PATCH 4/4] ARM: amba: Fix wrong indentation in driver_override_store() Geert Uytterhoeven
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.