Commit b3449087 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski

gpio: cdev: sanitize the label before requesting the interrupt

When an interrupt is requested, a procfs directory is created under
"/proc/irq/<irqnum>/<label>" where <label> is the string passed to one of
the request_irq() variants.

What follows is that the string must not contain the "/" character or
the procfs mkdir operation will fail. We don't have such constraints for
GPIO consumer labels which are used verbatim as interrupt labels for
GPIO irqs. We must therefore sanitize the consumer string before
requesting the interrupt.

Let's replace all "/" with ":".

Cc: stable@vger.kernel.org
Reported-by: default avatarStefan Wahren <wahrenst@gmx.net>
Closes: https://lore.kernel.org/linux-gpio/39fe95cb-aa83-4b8b-8cab-63947a726754@gmx.net/Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: default avatarKent Gibson <warthog618@gmail.com>
parent 4cece764
...@@ -1083,10 +1083,20 @@ static u32 gpio_v2_line_config_debounce_period(struct gpio_v2_line_config *lc, ...@@ -1083,10 +1083,20 @@ static u32 gpio_v2_line_config_debounce_period(struct gpio_v2_line_config *lc,
return 0; return 0;
} }
static inline char *make_irq_label(const char *orig)
{
return kstrdup_and_replace(orig, '/', ':', GFP_KERNEL);
}
static inline void free_irq_label(const char *label)
{
kfree(label);
}
static void edge_detector_stop(struct line *line) static void edge_detector_stop(struct line *line)
{ {
if (line->irq) { if (line->irq) {
free_irq(line->irq, line); free_irq_label(free_irq(line->irq, line));
line->irq = 0; line->irq = 0;
} }
...@@ -1110,6 +1120,7 @@ static int edge_detector_setup(struct line *line, ...@@ -1110,6 +1120,7 @@ static int edge_detector_setup(struct line *line,
unsigned long irqflags = 0; unsigned long irqflags = 0;
u64 eflags; u64 eflags;
int irq, ret; int irq, ret;
char *label;
eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS; eflags = edflags & GPIO_V2_LINE_EDGE_FLAGS;
if (eflags && !kfifo_initialized(&line->req->events)) { if (eflags && !kfifo_initialized(&line->req->events)) {
...@@ -1146,11 +1157,17 @@ static int edge_detector_setup(struct line *line, ...@@ -1146,11 +1157,17 @@ static int edge_detector_setup(struct line *line,
IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
irqflags |= IRQF_ONESHOT; irqflags |= IRQF_ONESHOT;
label = make_irq_label(line->req->label);
if (!label)
return -ENOMEM;
/* Request a thread to read the events */ /* Request a thread to read the events */
ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread, ret = request_threaded_irq(irq, edge_irq_handler, edge_irq_thread,
irqflags, line->req->label, line); irqflags, label, line);
if (ret) if (ret) {
free_irq_label(label);
return ret; return ret;
}
line->irq = irq; line->irq = irq;
return 0; return 0;
...@@ -1973,7 +1990,7 @@ static void lineevent_free(struct lineevent_state *le) ...@@ -1973,7 +1990,7 @@ static void lineevent_free(struct lineevent_state *le)
blocking_notifier_chain_unregister(&le->gdev->device_notifier, blocking_notifier_chain_unregister(&le->gdev->device_notifier,
&le->device_unregistered_nb); &le->device_unregistered_nb);
if (le->irq) if (le->irq)
free_irq(le->irq, le); free_irq_label(free_irq(le->irq, le));
if (le->desc) if (le->desc)
gpiod_free(le->desc); gpiod_free(le->desc);
kfree(le->label); kfree(le->label);
...@@ -2114,6 +2131,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) ...@@ -2114,6 +2131,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
int fd; int fd;
int ret; int ret;
int irq, irqflags = 0; int irq, irqflags = 0;
char *label;
if (copy_from_user(&eventreq, ip, sizeof(eventreq))) if (copy_from_user(&eventreq, ip, sizeof(eventreq)))
return -EFAULT; return -EFAULT;
...@@ -2198,15 +2216,23 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) ...@@ -2198,15 +2216,23 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
if (ret) if (ret)
goto out_free_le; goto out_free_le;
label = make_irq_label(le->label);
if (!label) {
ret = -ENOMEM;
goto out_free_le;
}
/* Request a thread to read the events */ /* Request a thread to read the events */
ret = request_threaded_irq(irq, ret = request_threaded_irq(irq,
lineevent_irq_handler, lineevent_irq_handler,
lineevent_irq_thread, lineevent_irq_thread,
irqflags, irqflags,
le->label, label,
le); le);
if (ret) if (ret) {
free_irq_label(label);
goto out_free_le; goto out_free_le;
}
le->irq = irq; le->irq = irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment