Received: by 10.223.185.116 with SMTP id b49csp4191319wrg; Mon, 26 Feb 2018 12:54:28 -0800 (PST) X-Google-Smtp-Source: AG47ELsIt4LZs2UzptdxpTzkav4QDHihaqHZLQQr5LI6MABh0UfxH1r6SvRLGnwk/1H1RwD5jbkW X-Received: by 10.98.185.11 with SMTP id z11mr1297916pfe.153.1519678468348; Mon, 26 Feb 2018 12:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519678468; cv=none; d=google.com; s=arc-20160816; b=mHlACB7PnuhazFHg1bqQcjfY73s4idVOwRT9TsSLTwH0wOmxImk44q20VTvTocAeAk g5HsxUinwMjsZz1esqZqDr4l3brllfZD0yt3c/ZlE6ubSxmbAcOYcKxaSMJfcSPRKBfM 7kI21XPNiJgNP/mXnz5vEHb39AvpN3uNGDzjSDXoLy4L3kDQRlHAuAKwSwEFKutJ5EnA VD6JV95DAfGWs8KnTzjaAHoJk4MPZCczaf687Sn7pKwhhpNDorMxVelZuOP02CFe/s8A zxkCSFjPMRrYkBctLMehC7xwO7P+D3+C27ilbbvg1HZF87ToLRVBGfLqpWg3/hgtMJe1 SPWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=F/3imOhuHt8t3jfHCsLWRtfxPSuxJO70JiC+1RrlN7Q=; b=FXKBANGg7kNsFXALH4GsaaEvk5c0pp3wFzE1SXOrn8M9pCThJ11TByyVgz6iVhtRMJ Lx+NqMGC9r5uUHqwx0za2nk2IoLNfYZmI7o17tu4GUVl6WJjc0QV2lRaoh+GYl4iuOdS xtpmWIg/cJjqgyTqKVdUZTwGnqBDY0BWYNC/YKbTLYHcWfXDzCU5jI4R16/FFNjS8Chz ZRQyjHjRwim8S0oMmH8GCxtagAl93p7yaM3fAFusN8KARQipljR+ymZIFYLHh2Q0OPeE 5ufS2naSLLzzv4IuH2D3HHudfZpZKwFyv5DuJY4Jx9cI3+dRrB3zcTpCzGRUzJjalklb qFwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11-v6si7483285plk.720.2018.02.26.12.54.11; Mon, 26 Feb 2018 12:54:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752811AbeBZUYH (ORCPT + 99 others); Mon, 26 Feb 2018 15:24:07 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34974 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751605AbeBZUYE (ORCPT ); Mon, 26 Feb 2018 15:24:04 -0500 Received: from localhost (clnet-b04-243.ikbnet.co.at [83.175.124.243]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 69949F78; Mon, 26 Feb 2018 20:24:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Getz , Lars-Peter Clausen , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.14 24/54] iio: adis_lib: Initialize trigger before requesting interrupt Date: Mon, 26 Feb 2018 21:22:01 +0100 Message-Id: <20180226202145.593337675@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180226202144.375869933@linuxfoundation.org> References: <20180226202144.375869933@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lars-Peter Clausen commit f027e0b3a774e10302207e91d304bbf99e3a8b36 upstream. The adis_probe_trigger() creates a new IIO trigger and requests an interrupt associated with the trigger. The interrupt uses the generic iio_trigger_generic_data_rdy_poll() function as its interrupt handler. Currently the driver initializes some fields of the trigger structure after the interrupt has been requested. But an interrupt can fire as soon as it has been requested. This opens up a race condition. iio_trigger_generic_data_rdy_poll() will access the trigger data structure and dereference the ops field. If the ops field is not yet initialized this will result in a NULL pointer deref. It is not expected that the device generates an interrupt at this point, so typically this issue did not surface unless e.g. due to a hardware misconfiguration (wrong interrupt number, wrong polarity, etc.). But some newer devices from the ADIS family start to generate periodic interrupts in their power-on reset configuration and unfortunately the interrupt can not be masked in the device. This makes the race condition much more visible and the following crash has been observed occasionally when booting a system using the ADIS16460. Unable to handle kernel NULL pointer dereference at virtual address 00000008 pgd = c0004000 [00000008] *pgd=00000000 Internal error: Oops: 5 [#1] PREEMPT SMP ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.9.0-04126-gf9739f0-dirty #257 Hardware name: Xilinx Zynq Platform task: ef04f640 task.stack: ef050000 PC is at iio_trigger_notify_done+0x30/0x68 LR is at iio_trigger_generic_data_rdy_poll+0x18/0x20 pc : [] lr : [] psr: 60000193 sp : ef051bb8 ip : 00000000 fp : ef106400 r10: c081d80a r9 : ef3bfa00 r8 : 00000087 r7 : ef051bec r6 : 00000000 r5 : ef3bfa00 r4 : ee92ab00 r3 : 00000000 r2 : 00000000 r1 : 00000000 r0 : ee97e400 Flags: nZCv IRQs off FIQs on Mode SVC_32 ISA ARM Segment none Control: 18c5387d Table: 0000404a DAC: 00000051 Process swapper/0 (pid: 1, stack limit = 0xef050210) [] (iio_trigger_notify_done) from [] (__handle_irq_event_percpu+0x88/0x118) [] (__handle_irq_event_percpu) from [] (handle_irq_event_percpu+0x1c/0x58) [] (handle_irq_event_percpu) from [] (handle_irq_event+0x38/0x5c) [] (handle_irq_event) from [] (handle_level_irq+0xa4/0x130) [] (handle_level_irq) from [] (generic_handle_irq+0x24/0x34) [] (generic_handle_irq) from [] (zynq_gpio_irqhandler+0xb8/0x13c) [] (zynq_gpio_irqhandler) from [] (generic_handle_irq+0x24/0x34) [] (generic_handle_irq) from [] (__handle_domain_irq+0x5c/0xb4) [] (__handle_domain_irq) from [] (gic_handle_irq+0x48/0x8c) [] (gic_handle_irq) from [] (__irq_svc+0x6c/0xa8) To fix this make sure that the trigger is fully initialized before requesting the interrupt. Fixes: ccd2b52f4ac6 ("staging:iio: Add common ADIS library") Reported-by: Robin Getz Signed-off-by: Lars-Peter Clausen Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/imu/adis_trigger.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/iio/imu/adis_trigger.c +++ b/drivers/iio/imu/adis_trigger.c @@ -47,6 +47,10 @@ int adis_probe_trigger(struct adis *adis if (adis->trig == NULL) return -ENOMEM; + adis->trig->dev.parent = &adis->spi->dev; + adis->trig->ops = &adis_trigger_ops; + iio_trigger_set_drvdata(adis->trig, adis); + ret = request_irq(adis->spi->irq, &iio_trigger_generic_data_rdy_poll, IRQF_TRIGGER_RISING, @@ -55,9 +59,6 @@ int adis_probe_trigger(struct adis *adis if (ret) goto error_free_trig; - adis->trig->dev.parent = &adis->spi->dev; - adis->trig->ops = &adis_trigger_ops; - iio_trigger_set_drvdata(adis->trig, adis); ret = iio_trigger_register(adis->trig); indio_dev->trig = iio_trigger_get(adis->trig);