Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1599661rda; Mon, 23 Oct 2023 19:01:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEl2z/Ri0evOIkVa7qPVXxelvMh0vpO0ruEpCFTQlXU/2Wxsih4SILiuDnDfUZlvx/QH6y X-Received: by 2002:a17:90a:c257:b0:27d:3260:9142 with SMTP id d23-20020a17090ac25700b0027d32609142mr8399368pjx.45.1698112907268; Mon, 23 Oct 2023 19:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698112907; cv=none; d=google.com; s=arc-20160816; b=bQDNKkYwF3yMfizXLfPU6ks+4mM8iHWEXovT+EEzCBABG+jbp1BCL7z3GwNkV8FsJS y51X6CMQnCD0X/ec7kJACoqYh1qTPnbqd6sVJy2Gpo5qctjnRyEG8Dt2anqg7jM8dxbg VN9XsCFjOLHNnb3C6AMMPbdDpUXfzho47XcmP+FuDCzhKp0B365gV4I9mUL6vRimOM9t E1UHMLNk2tPx+pbU1ETW7fAE6LaFgom0IBtUXvsFZW/C8tzgQurN22JcHV+9bm+8Wm6/ LajwIY4XgrGvYd/hUZi4eMErppfCMlRh12rGFsumY8riLpR8uOFtRT80uTawYt3ah5Ef q+2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:date:to:cc:from:subject:references :in-reply-to:content-transfer-encoding:mime-version:message-id :dkim-signature; bh=fc3NKMfZoje2hmQNMCXwrEeKB9yHVquKxP4o2hHyQ+A=; fh=QSxssOyQUPWz8G+bVqryCXL0b6UbmaiQIJpzRoqF2zM=; b=ZrBnjzLR9O4KUjjOn8XEF1q57kM59Ea8gw8bQ81jwgN2KKrhtVyFTsCTPV73RWqbHR Bzjqoug55eDNguCP0Nu2H6P6PPPkH6T+yzwlSnnV5XgFcmXn1mIH10L5YrrTKBCkZ6rV zeDAKmpZNqnPup7IpUFXLVgN8Kn8z7jiePv0j8Vx6GaqIIoSKnY3a7QLlmtTEjzqMq+G 6tPPnilUbpZDf4KKqdNNA6IR46wW+zmT5MKbFqld9p3G/ZbV46uLPQa3SmdM+Ytn099P CEnU8Q2emkpwbQQXvxSfBtKw2wXvYLI6Mse1D07luTs7or4L2eJFl27ZIUrY49Br8xsL goBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Pv5Cwg6l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z14-20020a17090ad78e00b0026810b074afsi10317701pju.3.2023.10.23.19.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 19:01:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Pv5Cwg6l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4A300806884E; Mon, 23 Oct 2023 19:01:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231865AbjJXCBn (ORCPT + 99 others); Mon, 23 Oct 2023 22:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231740AbjJXCBm (ORCPT ); Mon, 23 Oct 2023 22:01:42 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B928DC2 for ; Mon, 23 Oct 2023 19:01:39 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2750C433C7; Tue, 24 Oct 2023 02:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698112899; bh=fc3NKMfZoje2hmQNMCXwrEeKB9yHVquKxP4o2hHyQ+A=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=Pv5Cwg6lrfNB4MajdApvNEULjDz3t0D2/xLwROHqGAQ0KyWhnAq3U/HwPS07lav57 0RuuIPkEZCxv6FsT9lB1DD10IxtXfng+3fjyxJOAFuHJBhdrawOg3GJp6twfi1r0SK ADO2tr3Smk5HojfVBb0dRqABH7e8ld9VsbBdRPeL8+TwSOZ7NGmVmjSH6IXf58AUiV IzQzHFB0VOC90BRHf5tCREzTJhB5A+wR1rQj3Biykm1aXpIlgM33AtD2TWWZQQqHxj ej7u+EDYAcEYkC/wnM8e5y8pbx8IxAvbzqzBM8GxULHDiQ3MZBRPhEOP1XV3vxcNBa 79E//dVbSaOgg== Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20230717173934.1.If004a6e055a189c7f2d0724fa814422c26789839@changeid> References: <20230717173934.1.If004a6e055a189c7f2d0724fa814422c26789839@changeid> Subject: Re: [PATCH] spmi: mediatek: Fix UAF on device remove From: Stephen Boyd Cc: Yu-Che Cheng , Fei Shao , AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org To: James Lo , Matthias Brugger , Yu-Che Cheng Date: Mon, 23 Oct 2023 19:01:36 -0700 User-Agent: alot/0.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 23 Oct 2023 19:01:46 -0700 (PDT) Quoting Yu-Che Cheng (2023-07-17 02:39:35) > The pmif driver data that contains the clocks is allocated along with > spmi_controller. > On device remove, spmi_controller will be freed first, and then devres > , including the clocks, will be cleanup. > This leads to UAF because putting the clocks will access the clocks in > the pmif driver data, which is already freed along with spmi_controller. >=20 > This can be reproduced by enabling DEBUG_TEST_DRIVER_REMOVE and > building the kernel with KASAN. >=20 > Fix the UAF issue by using unmanaged clk_bulk_get() and putting the > clocks before freeing spmi_controller. >=20 > Reported-by: Fei Shao > Signed-off-by: Yu-Che Cheng > --- Applied to spmi-next