Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1143070pxv; Fri, 9 Jul 2021 19:22:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQdRHcuuVN3Woy1m9pZB5T3EEP/n/0809u0KwZvXtBsGeTP+YFIs2oVHb364nHTAp4qW/a X-Received: by 2002:a17:906:1cd5:: with SMTP id i21mr7203765ejh.478.1625883624340; Fri, 09 Jul 2021 19:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883624; cv=none; d=google.com; s=arc-20160816; b=ioL2U+GpEKLvNbUzbsnVAb1ts2H0bICKRwKZqkwzpmox6mAy6U2yOLo29ZAUp8Bz72 lyIVunN5py5EOOwWMuOAWpCn0qkTroe3vUfG/a8924TWhQHegh50QwpJkl6CTIuTizSS /crgF37Uk3RAM1gpNH7XbHCvGLq+PgUmK/I84GkY5YFmCjYaBRjjss3MEDJ7TJAbdZR+ MmNyxSq0QCVc5Ox6dqV7AN+OuEmeTcOeRRIJBx0c3Lp/RmklqMRvmNMOEsX1RPu+PXsA H2332CeDF9ClgwW5XUow4dCwvgf50aHS3GESH/+GuMzze9pUIldV48tDzeiUIUgHcJuD i5Rw== 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=pwrG2as4zStaDk4PrDsGjorxICULzhFlSqkyt5e+knM=; b=Dk3ZeApUbwNR9HKcIFDHcrlxdVY0t4F0m3alQkx7OrebPosFBCRIQ+9yOua/UWPksR K0HEsz4OjXlURZpv4/R/VLEUz/tZOz8jg0Zc8nMeZOaNgcdu0xN6zMeudtbZ8mu5LCpG dsvfgbdRaFrEDhqzxyzezfMywLJTxqNx7qX3sokxq6I9Mbuoac2hGeMrO1/cvjT7zcyR zPsXNtwLOfvbT24YLEoxZy1D/hXTI4tI89RSMnZv+154wciKW/By5f2L0K9LrQQ0rCMd l5wWGUU1SiZo6dB3wnmvR6aL0NVr3n+XCf4TND5Ww6Ea3E/K+7vre3ExU3TYwutDxGbV moQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KwDkHl/a"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hz17si9300060ejc.210.2021.07.09.19.19.54; Fri, 09 Jul 2021 19:20:24 -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=@kernel.org header.s=k20201202 header.b="KwDkHl/a"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232106AbhGJCVK (ORCPT + 99 others); Fri, 9 Jul 2021 22:21:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:37270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231886AbhGJCUx (ORCPT ); Fri, 9 Jul 2021 22:20:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E8678613CC; Sat, 10 Jul 2021 02:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883489; bh=4DYIJkBBNEgbBtLUIK/WIpKbeZB5/9WqbXBS6E8Bh54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwDkHl/a/xoP0nhUsLv/u8G9WyZyyBR6IILej+uA1qRIn14w1xTrVvkFESe/Nrh/I 5jlNjWz1H0yVDRu7yQ0fAngmvHmLQi25KGbiTiU2ZbKZrRALHInMdhiQtY/HDx2R+I A9yA+XW2Yzq3kE38qqmYFVL3a0wcUJ2qZeaUE8UgprQUfmi0qEoAkQuZF1HDo03Mrt PmdC+APC46up/XAxx/IiXtyhJVHFZxITzFJVB+O/ZeKhbKcDY84TvhnTEs2LWzWqct OHiMoRmWorkSAhqS/ve1TJn0iZ4AzvCVvl9r8lqc/zD9p99tsZHcFyfTV56nkN7Vtf 7s1F4GZSASiWw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Lv Yunlong , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 5.13 014/114] misc/libmasm/module: Fix two use after free in ibmasm_init_one Date: Fri, 9 Jul 2021 22:16:08 -0400 Message-Id: <20210710021748.3167666-14-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710021748.3167666-1-sashal@kernel.org> References: <20210710021748.3167666-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 4edad6c445d3..dc8a06c06c63 100644 --- a/drivers/misc/ibmasm/module.c +++ b/drivers/misc/ibmasm/module.c @@ -111,7 +111,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); @@ -131,8 +131,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