Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp836776pxb; Mon, 25 Oct 2021 20:12:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzItD+t5stjKkND0OjbWuyfg1RF4S1LmwtaLKJPJBSnovOjCJ446X3+NNw8/rr91KYSJSmJ X-Received: by 2002:a17:90b:38ca:: with SMTP id nn10mr16786322pjb.190.1635217976307; Mon, 25 Oct 2021 20:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635217976; cv=none; d=google.com; s=arc-20160816; b=QnJN8QWK6t95SOXvjiz3OHMaLG2TsvFb8JTSJJ6ucEELa59W/xgUv35ExmcDjOafdF WmQ39N3qUuH+WNrrYShMgBgQkcSLz8P39yov/Ai2a2w+1eeMa7YjVpt3ilskNZFSDsG9 CCOs5SC1zOj3+B6HNqSMx/nmI58zYg/2+vFBNlKuL68X4xXTru1c8MH7wL8HW8rIcgOk w6dGOQz/wtoLRFDe6vWAKvu+Emy59v65Tf48dnbXGTLkhYkW5X7oOoR2cyCsYpA4pyjI B4/AbRVTL4+UNQQzm1JLVYTBgAJiVwoLhUkaBsfbxW+uaCdAjnBoq+r5qHHxHsk5mpu4 Ipqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5MjhOsT6vsgE3PRSqOL/b2QlSnU9cwQAuPv26ujxKj8=; b=RINjx3bjHbbN1sGVuw8LALuX2PoFcJibfB4W5Pq0DpiJ89IcExnyYvOYSFB0WUW3An gQOZDdOlFdYjpJyhH8whC2ehHuROI1ynTg+mk4LaUWCYFwjBJHp5bNFobBUtCBjoB0qm b8plC8W2JJk6/Ykf/fRdDUk+K3TvJ14JJQhOf2Si4DN77bOefUpx8wYsL/+gb0Fvz0G5 B2qmnKpbZRL4fm5ZPXhfQg1JzOvTtp/PDWAgrAsm5sMq19i95YvKM0vJ9k4FdXAv596X fgC5xUfKzTQ+NqBoWdu+lf/H40jaSU6uohVAB/htidKlHGD2AyE4dkQDNc1VnRN8AToW bAaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eYsJQ29k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lr6si4719212pjb.179.2021.10.25.20.12.43; Mon, 25 Oct 2021 20:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eYsJQ29k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235094AbhJYXlM (ORCPT + 99 others); Mon, 25 Oct 2021 19:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233864AbhJYXlK (ORCPT ); Mon, 25 Oct 2021 19:41:10 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D380C061745 for ; Mon, 25 Oct 2021 16:38:47 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id x66so12406798pfx.13 for ; Mon, 25 Oct 2021 16:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5MjhOsT6vsgE3PRSqOL/b2QlSnU9cwQAuPv26ujxKj8=; b=eYsJQ29kvLlHJ1I8kvPlWWSSKos/TDJWWWWBpksa5ij/buKU9ESOTC5u7sXTZWXcE5 eYRcZ/gvWStncpEOEy5XQQaBBRTUa09oqxtE7yKWvj7pSXrxm0iIkbbvIV0czZIB9Qlf RjQ8OlGDSrwX9GvjtR9HgzBzTf3r2dTRQVwwo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5MjhOsT6vsgE3PRSqOL/b2QlSnU9cwQAuPv26ujxKj8=; b=Oc87F3kxW4QwE4lvumkySgqTWyB5EeHAfWYFIV2nMbbbLVFeDXqZQoRtobz/qNSJUw L2z3D3THHHQDszg4nmJxjsJS/7Dxj4g1IEcGmOH95FbaGuuq20f6Gqr5GYAdpH89t+K+ akx1AaixFBPbPd3b/4tObx1PfJ/OOVCjIUp2ADRUnnbjsfkYM7PbUKUPZo1FrOExRbwU 2WwN6kwvw9ZjiiVrH4MkxJUq/BnAhha20xUEYr2cEB9vZaWnt5kbjWixAcRMW9K6kaAQ OXkGVbOXsSwOULHFzv1UtKNojqf+cbpy/n0yYbYu1noo4aWO9SXtCu/VsDYDld8M9UF1 QH4g== X-Gm-Message-State: AOAM5308FB4xd5ERY18EPgQBH6xdo/adoYXm15oPGjiXes4grKDZ7RuN 5et3n2F8P34u5IL96djHC5oxMA== X-Received: by 2002:a05:6a00:22d1:b0:47b:e629:3f39 with SMTP id f17-20020a056a0022d100b0047be6293f39mr12333728pfj.80.1635205126753; Mon, 25 Oct 2021 16:38:46 -0700 (PDT) Received: from sujitka-glaptop.hsd1.ca.comcast.net ([2601:646:8e00:b2f0:eac2:13a5:2214:747b]) by smtp.gmail.com with ESMTPSA id gn1sm5954453pjb.34.2021.10.25.16.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 16:38:46 -0700 (PDT) From: Sujit Kautkar To: Andy Gross , Ohad Ben-Cohen Cc: Stephen Boyd , Sibi Sankar , Bjorn Andersson , Sujit Kautkar , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org Subject: [PATCH v2 1/2] rpmsg: glink: Fix use-after-free in qcom_glink_rpdev_release() Date: Mon, 25 Oct 2021 16:37:52 -0700 Message-Id: <20211025163739.v2.1.Id19324ea36b4cf89faf98bf520bc6b6f01240433@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20211025233751.1777479-1-sujitka@chromium.org> References: <20211025233751.1777479-1-sujitka@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org qcom_glink_rpdev_release() sets channel->rpdev to NULL. However, with debug enabled kernel, qcom_glink_rpdev_release() gets delayed due to delayed kobject release and channel gets released by that time and triggers below kernel warning. To avoid this use-after-free, add a condition to checks if channel was already released. | BUG: KASAN: use-after-free in qcom_glink_rpdev_release+0x54/0x70 | Write of size 8 at addr ffffffaba438e8d0 by task kworker/6:1/54 | | CPU: 6 PID: 54 Comm: kworker/6:1 Not tainted 5.4.109-lockdep #16 | Hardware name: Google Lazor (rev3+) with KB Backlight (DT) | Workqueue: events kobject_delayed_cleanup | Call trace: | dump_backtrace+0x0/0x284 | show_stack+0x20/0x2c | dump_stack+0xd4/0x170 | print_address_description+0x3c/0x4a8 | __kasan_report+0x144/0x168 | kasan_report+0x10/0x18 | __asan_report_store8_noabort+0x1c/0x24 | qcom_glink_rpdev_release+0x54/0x70 | device_release+0x68/0x14c | kobject_delayed_cleanup+0x158/0x2cc | process_one_work+0x7cc/0x10a4 | worker_thread+0x80c/0xcec | kthread+0x2a8/0x314 | ret_from_fork+0x10/0x18 Signed-off-by: Sujit Kautkar --- (no changes since v1) drivers/rpmsg/qcom_glink_native.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index e1444fefdd1c0..cc3556a9385a9 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -270,6 +270,7 @@ static void qcom_glink_channel_release(struct kref *ref) spin_unlock_irqrestore(&channel->intent_lock, flags); kfree(channel->name); + channel = NULL; kfree(channel); } @@ -1372,8 +1373,10 @@ static void qcom_glink_rpdev_release(struct device *dev) { struct rpmsg_device *rpdev = to_rpmsg_device(dev); struct glink_channel *channel = to_glink_channel(rpdev->ept); + if (channel) { + channel->rpdev = NULL; + } - channel->rpdev = NULL; kfree(rpdev); } -- 2.31.0