From nobody Tue Apr 7 08:08:51 2026 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 1CC8EC433FE for ; Thu, 13 Oct 2022 13:12:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229879AbiJMNMz (ORCPT ); Thu, 13 Oct 2022 09:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbiJMNMv (ORCPT ); Thu, 13 Oct 2022 09:12:51 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A786914D8D8 for ; Thu, 13 Oct 2022 06:12:47 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Mp8vr6jCmzmVBT; Thu, 13 Oct 2022 21:08:08 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 13 Oct 2022 21:12:45 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 13 Oct 2022 21:12:44 +0800 From: Yang Yingliang To: CC: , , Subject: [PATCH] platform/loongarch: laptop: fix possible UAF in generic_acpi_laptop_init() Date: Thu, 13 Oct 2022 21:12:09 +0800 Message-ID: <20221013131209.775969-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Current the return value of 'sub_driver->init' is not checked, if sparse_keymap_setup() called in the init function fails, 'generic_inputdev' is freed, then it willl lead a UAF when using it in generic_acpi_laptop_init(). Fix it by checking return value. Set generic_inputdev to NULL after free to avoid double free it. Fixes: 6246ed09111f ("LoongArch: Add ACPI-based generic laptop driver") Signed-off-by: Yang Yingliang --- drivers/platform/loongarch/loongson-laptop.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/platform/loongarch/loongson-laptop.c b/drivers/platfor= m/loongarch/loongson-laptop.c index f0166ad5d2c2..a665fd1042ac 100644 --- a/drivers/platform/loongarch/loongson-laptop.c +++ b/drivers/platform/loongarch/loongson-laptop.c @@ -448,6 +448,7 @@ static int __init event_init(struct generic_sub_driver = *sub_driver) if (ret < 0) { pr_err("Failed to setup input device keymap\n"); input_free_device(generic_inputdev); + generic_inputdev =3D NULL; =20 return ret; } @@ -502,8 +503,11 @@ static int __init generic_subdriver_init(struct generi= c_sub_driver *sub_driver) if (ret) return -EINVAL; =20 - if (sub_driver->init) - sub_driver->init(sub_driver); + if (sub_driver->init) { + ret =3D sub_driver->init(sub_driver); + if (ret) + goto err_out; + } =20 if (sub_driver->notify) { ret =3D setup_acpi_notify(sub_driver); --=20 2.25.1