Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2563474lqp; Mon, 25 Mar 2024 02:43:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXJ/Bs4//nNJ5lWgRTCfvIJJLkgeRxj7yJdFgKb2hVjEvAJSIpsnZ3FItySC8KveLMoZqvH3j0yw/Rs5gQH1gUC/OMDNYpQCbFjpnw1bQ== X-Google-Smtp-Source: AGHT+IGuLelypmQgGg8HztTlKY1lfchSR8SOz7oRvfN/tgjhI2/wiOiOQpm7c4YCPSXkBJZ8qkS/ X-Received: by 2002:a17:906:383:b0:a46:ed72:6bb4 with SMTP id b3-20020a170906038300b00a46ed726bb4mr4206477eja.72.1711359832636; Mon, 25 Mar 2024 02:43:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711359832; cv=pass; d=google.com; s=arc-20160816; b=bU+iyP1s82eEn9ORbvG9lJbnZvFeu/APvTSKiFaOYIaG/9YAJAyRTRdfn1qSuUe7k6 MQMQeeFBJNQWyzG7Tb8rkfs4+gxpOmZycrRfcTT5c5qXsrXelW7J3hnA+PJDhYGBVrJq DReATgG6plXK+CK72XlR+gYkrxKDxt/pqxm7aofLQZsBM+jC4k85PB5Jl0rTGNCFksa+ RlJdpFphrQT7F1tXDN0XZaiNbM22ohCXp55kFJDj+4ipDRkBdIBh9CW0+bCHazS0QKM+ LwIH6c2ydbPnyC3tCmWgmkyq4MLvQw3UAkZfYusFKHFXtuv1K+gjjlvRGOW9MIH4YZqB SCJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Bpqb9ULDIv/IkPbWQ0apeTjM4ros+KAlPWry4I3ZfgA=; fh=Iaxv0Y+zZM9vOI7nj3ybg9KYuVc4s5Mf9IYDNRw2nFI=; b=SIAAy+Z7UmC5UVfNlqMNTDvnXmCwi3kY4mKTA+FxS/dnj2ScpTVe8NC1Ezc55LqxVI CRUN6NQ422VcHE9esSaK/DkLcQoq24vVOTESgbhk1l6JWmW17C+SrN4OhqynAhXjBWR2 TyuL0KLANjKS6wUk9EeAaN2Dr7THlR55F/Emj40bmi2viZmeub4aNFScztj3Ai362KZa +eldr+TMt+8xCUW9biEv40I4KJZkWGE6vPVspVyLe8J/mnrGxM01nWCxMA1X984oHEmK MsBIorwS1vdiXO0li5svlyKv9/beyfUF0L7qPdJBC/zvz7Oib/REGmTRrYAG0oNcEs7i JiRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jLJgB7p0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115897-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c17-20020a170906155100b00a4660932871si2259604ejd.887.2024.03.25.02.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:43:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115897-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jLJgB7p0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115897-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B5DB11F32AEF for ; Mon, 25 Mar 2024 09:42:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18A2C38663F; Mon, 25 Mar 2024 03:03:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jLJgB7p0" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C04B01474AF; Sun, 24 Mar 2024 23:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322089; cv=none; b=GespaH/4L01nHCEaeozITkoOQDJ+CGzQIq6go8q6kLu3sqB37l8zL7QpwE8VdgWndWEIOgI8O06oDJQV4bgrUmlyDnIamEnqK8Bzv4pxF5xnL9dt5oijczBN5Aqf2dszTgWyPVDNjFMGLZUmsAg4FxZzpvwHEL101VKNsC7bhMY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322089; c=relaxed/simple; bh=TLtPW5ESOsYge5j1u9lbdb9PepDoBxuqqQPnetMEBfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JVRDu4lIdNh4dw57VpskKOp/HL2btLGNW0oocpzyhWqb+VN0Aa6zLeImlre4NXs4jVy+LYc2ipZcu9kXOUd1jDyXpILnKUZUVyM0tOsvd8Sz50Mt7lpLD8Srie7TPt74YfHFO46I7b3bfu5wfj+e7W0hRUy5MywxV2mZCdyjXyU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jLJgB7p0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E330EC43390; Sun, 24 Mar 2024 23:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322089; bh=TLtPW5ESOsYge5j1u9lbdb9PepDoBxuqqQPnetMEBfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLJgB7p0bLCwIq6Dji//G9uSsDhGcEHhJKznvuNQrwQVSx/mhssviaVSSZvsaTrka 1SU7N0KJ2nbPGHp3oAVTfcc6+lkZryghZ8vIg++sEdRwaVVH2JnLbZAZNNJNcP/N7e +c9mMhQjAy+v+ioT9U4aMAU22uYuGuTgF8ffF9eEhU98avnZ7NjnrLo0IYnw1ABBm9 vra9XOC3C9W3pvvXUIiZNWoSiQORRlxffOzkJsyttRZPUrhkbLZssHp89LdAvNtPwL /pyJwoB/Qze9gswUWcTrqW+DhmepLrrrjG2F+JoGV1ID9b5ZbOKFksH/9paTFxxnGv xfRTgPMXVOrrg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andre Przywara , Cristian Marussi , Sudeep Holla , Sasha Levin Subject: [PATCH 6.1 163/451] firmware: arm_scmi: Fix double free in SMC transport cleanup path Date: Sun, 24 Mar 2024 19:07:19 -0400 Message-ID: <20240324231207.1351418-164-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Andre Przywara [ Upstream commit f1d71576d2c9ec8fdb822173fa7f3de79475e9bd ] When the generic SCMI code tears down a channel, it calls the chan_free callback function, defined by each transport. Since multiple protocols might share the same transport_info member, chan_free() might want to clean up the same member multiple times within the given SCMI transport implementation. In this case, it is SMC transport. This will lead to a NULL pointer dereference at the second time: | scmi_protocol scmi_dev.1: Enabled polling mode TX channel - prot_id:16 | arm-scmi firmware:scmi: SCMI Notifications - Core Enabled. | arm-scmi firmware:scmi: unable to communicate with SCMI | Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 | Mem abort info: | ESR = 0x0000000096000004 | EC = 0x25: DABT (current EL), IL = 32 bits | SET = 0, FnV = 0 | EA = 0, S1PTW = 0 | FSC = 0x04: level 0 translation fault | Data abort info: | ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 | CM = 0, WnR = 0, TnD = 0, TagAccess = 0 | GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 | user pgtable: 4k pages, 48-bit VAs, pgdp=0000000881ef8000 | [0000000000000000] pgd=0000000000000000, p4d=0000000000000000 | Internal error: Oops: 0000000096000004 [#1] PREEMPT SMP | Modules linked in: | CPU: 4 PID: 1 Comm: swapper/0 Not tainted 6.7.0-rc2-00124-g455ef3d016c9-dirty #793 | Hardware name: FVP Base RevC (DT) | pstate: 61400009 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) | pc : smc_chan_free+0x3c/0x6c | lr : smc_chan_free+0x3c/0x6c | Call trace: | smc_chan_free+0x3c/0x6c | idr_for_each+0x68/0xf8 | scmi_cleanup_channels.isra.0+0x2c/0x58 | scmi_probe+0x434/0x734 | platform_probe+0x68/0xd8 | really_probe+0x110/0x27c | __driver_probe_device+0x78/0x12c | driver_probe_device+0x3c/0x118 | __driver_attach+0x74/0x128 | bus_for_each_dev+0x78/0xe0 | driver_attach+0x24/0x30 | bus_add_driver+0xe4/0x1e8 | driver_register+0x60/0x128 | __platform_driver_register+0x28/0x34 | scmi_driver_init+0x84/0xc0 | do_one_initcall+0x78/0x33c | kernel_init_freeable+0x2b8/0x51c | kernel_init+0x24/0x130 | ret_from_fork+0x10/0x20 | Code: f0004701 910a0021 aa1403e5 97b91c70 (b9400280) | ---[ end trace 0000000000000000 ]--- Simply check for the struct pointer being NULL before trying to access its members, to avoid this situation. This was found when a transport doesn't really work (for instance no SMC service), the probe routines then tries to clean up, and triggers a crash. Signed-off-by: Andre Przywara Fixes: 1dc6558062da ("firmware: arm_scmi: Add smc/hvc transport") Reviewed-by: Cristian Marussi Link: https://lore.kernel.org/r/20240126122325.2039669-1-andre.przywara@arm.com Signed-off-by: Sudeep Holla Signed-off-by: Sasha Levin --- drivers/firmware/arm_scmi/smc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c index ac0bd51ef16a2..42ea308a2c1d5 100644 --- a/drivers/firmware/arm_scmi/smc.c +++ b/drivers/firmware/arm_scmi/smc.c @@ -171,6 +171,13 @@ static int smc_chan_free(int id, void *p, void *data) struct scmi_chan_info *cinfo = p; struct scmi_smc *scmi_info = cinfo->transport_info; + /* + * Different protocols might share the same chan info, so a previous + * smc_chan_free call might have already freed the structure. + */ + if (!scmi_info) + return 0; + /* Ignore any possible further reception on the IRQ path */ if (scmi_info->irq > 0) free_irq(scmi_info->irq, scmi_info); -- 2.43.0