Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2373546lqp; Sun, 24 Mar 2024 16:26:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUP8fuGEXQCx+AUBA5BnLfCdbvCYqx64lwvKyYW3eoVSum/lLZfH4+5i+5Hu3LHPeMgcK3+w9xWnPrZeCokD+bxJ+U1vmKQql4EzRLQlA== X-Google-Smtp-Source: AGHT+IFHTsblV7h3VJcS6UF1YJq0Aie4QLrYnYyAC1QTvxsNdabg7sgLi3GHIB8snbKals+wp7Bq X-Received: by 2002:a05:6358:789:b0:17d:daa2:740e with SMTP id n9-20020a056358078900b0017ddaa2740emr6350813rwj.17.1711322765814; Sun, 24 Mar 2024 16:26:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711322765; cv=pass; d=google.com; s=arc-20160816; b=Z0wBjpf8ldtFTedo1TXQzhw3YyISKUKoRjXgg/ijHghEui2cN2U3mZ696KPfvsyj+R s4lMQNRf8Ew8T8HVVDrm9EkzVGvARUf5/MNW8UAmbKzVGb8mw9aFltR4b713mIR+SzSI eJgYO5ddnmd0l8ZzFvHDMxtwXRycsMZPMPo1C7QYEkUK5A8qRcvPKKiTGkK2vwiNmrcl qm8WmjSazTTkjiPY3YLPT5v4lGd9qqekY6ScG6bRM0L4nKkBjNhrM3vr1r5imxwTADe6 e+jHf47AfH4breFQEr4MODTfw597qlb2oD1soAJJu4LjpaBELp1qIGQvWjGurRDjNIng s31Q== 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=wW43op+r97RUBsSAwlmgzi/QdkeCYJTIZ0BZHAPNcsg=; fh=Iaxv0Y+zZM9vOI7nj3ybg9KYuVc4s5Mf9IYDNRw2nFI=; b=ttte4qd13vXza0k6tOusFoKW1Kg4jHi5Ic9lxaOMt7FKBquIUOcmQ8XDlNrwvO0AQS UxKp/CDK0xHjcOJ2+uYZcWlEp9Doh3oGScZO2IANKthNdiTmH8ZdSdOAM6blU3xeJGYZ H5oQtsFogG44+uiIcu9gTDsoQRzNw4TwyFGS9mAdLvjX98WO6VREY/WjVYL+Tan9Xduf tTyUhMNrMYgJVJ3zRk/PllgNOxG56do7vOqkgbTTr1x8S4mjmR53jS019bvZ9Noea0si uMQXec1sLytVcwBorDs0RJ+ZAq7FaPXwfJgcfMMj6SXAK54XPtT039nzNWyybnT6qU6d Dy3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WxzNdXKX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113112-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113112-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m14-20020a17090ab78e00b002a06eb75d96si761697pjr.115.2024.03.24.16.26.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:26:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113112-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WxzNdXKX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113112-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113112-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EACCD2824D5 for ; Sun, 24 Mar 2024 23:24:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35884159593; Sun, 24 Mar 2024 22:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WxzNdXKX" 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 406D1159579; Sun, 24 Mar 2024 22:38:39 +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=1711319920; cv=none; b=XIf60F24KzopgwVSQKQwQZWyxcF69NiuxkUeJxaI2HzjpM/sFIpFbFFBBrt2ZR4Z6pkew182zWbwkOwkdJeADneeldore+uUWtqu5oThdK+1afUIhKi9RUxwTem86gYggzxQBSpq+CGtA+z5awI9qbZriM7Ogw0IJSJYR1qHqK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319920; c=relaxed/simple; bh=1lwHRMfdeOG67Fs2sEkZD3y3XqkdjZSm0N3AdDXg11g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iFlHsx1vHVzol7xmUNet1rHSLvrSVzsFtAwSc4YRJE9sCP452IrvsDvvpTe70+Y22cJukXDAtFFwjeNHUT4PfZQnXreBgPK9FR06cOtWW0vGHBBmmoMhEGr28CbWwLYkC663gGVNiMDqGNvJ/EH1XamIkjJI66KSPIsmML+03tw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WxzNdXKX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0564DC433C7; Sun, 24 Mar 2024 22:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319919; bh=1lwHRMfdeOG67Fs2sEkZD3y3XqkdjZSm0N3AdDXg11g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WxzNdXKX8DofVamfeg5k75uCmAfvNP7d+YisU30BHzCIRJPBiYRO7cpRaSNedS01d p4wg2nF0h/xZt3cM9vhjds7eTVjb8yl4LtNgLBTqHfVbcy0ExI3G+wOU7LKj90s8PL IarUiu9AgKeanJj4/0yax/C9aHUxC9+fGM+E3iw7EDmpgIk+D4bvva1WquLeSu0wZZ fHHN7W3My64LzVD5OoimyTDQ8ZF+QkmzGtIG8QK95w+8YJ7eQLF0qT7HaGprz6dSM9 /mmH7WyXth+R4CnikruUaFGoe4cSIZHtBTy6WAHbAet+SgXoshIv68E4dD5iLOo2LN UWdSm7LRUpuZA== 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.8 225/715] firmware: arm_scmi: Fix double free in SMC transport cleanup path Date: Sun, 24 Mar 2024 18:26:44 -0400 Message-ID: <20240324223455.1342824-226-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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 7611e9665038d..39936e1dd30e9 100644 --- a/drivers/firmware/arm_scmi/smc.c +++ b/drivers/firmware/arm_scmi/smc.c @@ -214,6 +214,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