From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 038DEC433EF for ; Mon, 13 Dec 2021 09:39:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234652AbhLMJjR (ORCPT ); Mon, 13 Dec 2021 04:39:17 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:33188 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234916AbhLMJhn (ORCPT ); Mon, 13 Dec 2021 04:37:43 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id DB3F0CE0AE2; Mon, 13 Dec 2021 09:37:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80DFCC341CE; Mon, 13 Dec 2021 09:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1639388260; bh=oPwb0I/EY2RdhJXQxozcpuGip1/RlJsShWEhk3WHm/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vrwwf4CpVEFyGadgjMoCQsi397e2ccvU1LphOmfGXMQBXAuGYXAODi6yLdKxSxuA4 IU0cmRy0cdeXhvjt6pcGykp8kk45+nTzcjjGsRJbE832qr9nu9AysmQZ1ygSZqV3jf dn5oslOuuB3K6sNHmFPP8eIDubSWPPDUIw5BQIg4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.14 42/53] iio: mma8452: Fix trigger reference couting Date: Mon, 13 Dec 2021 10:30:21 +0100 Message-Id: <20211213092929.759714106@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211213092928.349556070@linuxfoundation.org> References: <20211213092928.349556070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lars-Peter Clausen commit cd0082235783f814241a1c9483fb89e405f4f892 upstream. The mma8452 driver directly assigns a trigger to the struct iio_dev. The IIO core when done using this trigger will call `iio_trigger_put()` to drop the reference count by 1. Without the matching `iio_trigger_get()` in the driver the reference count can reach 0 too early, the trigger gets freed while still in use and a use-after-free occurs. Fix this by getting a reference to the trigger before assigning it to the IIO device. Fixes: ae6d9ce05691 ("iio: mma8452: Add support for interrupt driven triggers.") Signed-off-by: Lars-Peter Clausen Link: https://lore.kernel.org/r/20211024092700.6844-1-lars@metafoo.de Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/accel/mma8452.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -1396,7 +1396,7 @@ static int mma8452_trigger_setup(struct if (ret) return ret; - indio_dev->trig = trig; + indio_dev->trig = iio_trigger_get(trig); return 0; }