Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3772043pxv; Mon, 19 Jul 2021 08:23:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMYW7zgr/Va16ZesTIixOBQTQKXtnP6tQa8E3dd7NiMOWFdrPNR1Mk/6zXzqtcm1WWBFUT X-Received: by 2002:a05:6638:2656:: with SMTP id n22mr22012956jat.64.1626708210813; Mon, 19 Jul 2021 08:23:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708210; cv=none; d=google.com; s=arc-20160816; b=fKYAwfb0JsT6+O6F3sWI1LqTirrBx4FYCJJ8Ry7iUUChE/GLhFVpfFKmEUwVhVLPYG ODegN8wVxT3VuYUuryYE2T8PITwUEvz7LhlyhsJ/dwZYPpIh19F5tG1HE+QcEUF+R+rk 9Enkn6mpjJo2vRZ726TNvQaHHWi9n4/To8T3TC4/YSvRl/mECnGqO+gzlDVGNi08UOTB 1hWVacA6/w+BcfEJFCqxGmhkXagbQJrjPbCAfcyepskUNIyCys7Vug6/eUYby2OUJswN HMadJIEG+YiVPRWNRxmQLkCdzVC/wwq4JhT2VyiTF1mXIXNO1Gucf2OxmII1MXpaty/q Uvcg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z8h20IX7kleVhA9F4NxTu2tjbWFh3OGz/FHrFlPCIp4=; b=i39gGZEPUuAPvsCkqmmKLed9KBQ/Z8vz5Ht3I/4GJDBrQMoCdt9PUfYhQCHV0lj7TA L/U/8RhJm1xxFhN/bMpybrawU1iWEMs1iaV8gT/REMuHi2AC9KT45I8BppUpZZTwuG4e aLkNBvkxrIAJ7PksVdeHQzvkfR+fv6dGlkr2hvNARmXmXhc40u6o9SHRJxu4J+NLphAi RuDLznO33zvr3W11uxlGKqaQeC09mXjiuAJ9xVooeQvWS+PO7rXbGbsE/My4LtC7CSXD D/bnFDWnSGGhcLByWDCA61z+y6lPysmHccinHpTEmoT+py4xIVdjI4lUfhIovZq/6niA ricA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=S8batHSe; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q17si21482112ilm.115.2021.07.19.08.23.17; Mon, 19 Jul 2021 08:23:30 -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=@linuxfoundation.org header.s=korg header.b=S8batHSe; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245252AbhGSOmF (ORCPT + 99 others); Mon, 19 Jul 2021 10:42:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:46648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245202AbhGSOax (ORCPT ); Mon, 19 Jul 2021 10:30:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 001F260551; Mon, 19 Jul 2021 15:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707490; bh=NmpHhKxyWabwxzoQk+F8jXQUcqsTQj1VPDk0XMEuu2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S8batHSesqTayHIm7gaAkC0IUZpHCOJGkx6HaQFLOiMuW9xhLguVFldjWeU1oSyes PJd/sGVV2HwgFW5VH8zDArmFpbX2iwmYLX9p7Ghw9JzHaa2D20C4hmuZBC/UTkzRJx fxsSyHYBOIQTfGi7UQXqBu9sowQTNY718udJJBc0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Sasha Levin Subject: [PATCH 4.9 186/245] misc/libmasm/module: Fix two use after free in ibmasm_init_one Date: Mon, 19 Jul 2021 16:52:08 +0200 Message-Id: <20210719144946.411944919@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 7272b591c4cb9327c43443f67b8fbae7657dd9ae ] In ibmasm_init_one, it calls ibmasm_init_remote_input_dev(). Inside ibmasm_init_remote_input_dev, mouse_dev and keybd_dev are allocated by input_allocate_device(), and assigned to sp->remote.mouse_dev and sp->remote.keybd_dev respectively. In the err_free_devices error branch of ibmasm_init_one, mouse_dev and keybd_dev are freed by input_free_device(), and return error. Then the execution runs into error_send_message error branch of ibmasm_init_one, where ibmasm_free_remote_input_dev(sp) is called to unregister the freed sp->remote.mouse_dev and sp->remote.keybd_dev. My patch add a "error_init_remote" label to handle the error of ibmasm_init_remote_input_dev(), to avoid the uaf bugs. Signed-off-by: Lv Yunlong Link: https://lore.kernel.org/r/20210426170620.10546-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/ibmasm/module.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/misc/ibmasm/module.c b/drivers/misc/ibmasm/module.c index 6b3bf9ab051d..706decef68a0 100644 --- a/drivers/misc/ibmasm/module.c +++ b/drivers/misc/ibmasm/module.c @@ -123,7 +123,7 @@ static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) result = ibmasm_init_remote_input_dev(sp); if (result) { dev_err(sp->dev, "Failed to initialize remote queue\n"); - goto error_send_message; + goto error_init_remote; } result = ibmasm_send_driver_vpd(sp); @@ -143,8 +143,9 @@ static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) return 0; error_send_message: - disable_sp_interrupts(sp->base_address); ibmasm_free_remote_input_dev(sp); +error_init_remote: + disable_sp_interrupts(sp->base_address); free_irq(sp->irq, (void *)sp); error_request_irq: iounmap(sp->base_address); -- 2.30.2