Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2696431pxy; Mon, 3 May 2021 06:09:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/kk2fKQq7ztrlCWXad6XYglXjhsiX5IrWuif16lIlTJYBFkpD/P88YLYI5aPuzcWffsCb X-Received: by 2002:a17:902:d4c2:b029:ed:4a62:abda with SMTP id o2-20020a170902d4c2b02900ed4a62abdamr19919368plg.5.1620047351277; Mon, 03 May 2021 06:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620047351; cv=none; d=google.com; s=arc-20160816; b=ySKKf0xlUiPGl70YKCnakT7A//kVJMe3+MVhxXMo5s9lU7xyWI66rrfapVJ6BXi5ex PaoBSnRHybFbgj0uBLkT0AJ4PNcb7m2pESGVfK0XTRW75945CnfprQso+g7StgD2kaJp AajoPPNOhL4Op+WUQd5cFMpJQjXE4DHwD08kcIafjbF3q65InljtAQpfzkvOUYkkHphD ryUTn+oVuTAIweDSAfYtabIp4CbOL7ulBmaZU/0XAj7DTXl6C9FHhdaGs8sxgo4vF25l Gmv/2tOhcLtFiEUzeYiZAUEIPM2X5dbxZCKH7h5wDafF1la8wDQN1nTOJxSlXcfsCN9d zDsQ== 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=LG95qI7NQg42waKpKpnJPVl53EAtdlBsoZa9OhEbXyw=; b=QkpTGeyiImykXXU9VBtvJq4UENxiYpIoCVGKJPhSwSFqAwBaQKMp+BIzV5YwnrHSU+ 8dJB2iMVsgO1OfoCtrWoLz04yT+8asQYEd8Mi9KiafI95PLCae5iUAkSKig9KQ3slVkC 7GYQbyvJgiVSrbkwUl0TXNLajjO+4Rpx1PYjsEPrX51M88B+ITLySnK8KykmiZSjiEAh BoUhkxeqPDgkkUXODFPUJG6H1oQUA5VdbjVk7ijrKWZIoVI7PWSDMQlTyeQVD+/+hrFm pkXCBJ7hw0ugaOhTWcpRz56hce7Wov8wjsB6HH4+jNnzHXvyuutSferlZvKs7SLviPW1 PTPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="L1/WZhe1"; 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 fz20si20640318pjb.58.2021.05.03.06.08.29; Mon, 03 May 2021 06:09:11 -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="L1/WZhe1"; 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 S233763AbhECMBt (ORCPT + 99 others); Mon, 3 May 2021 08:01:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:35650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233884AbhECMBF (ORCPT ); Mon, 3 May 2021 08:01:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1928361249; Mon, 3 May 2021 12:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620043210; bh=z4jA2YSG6DY4IEYnUj3gPzy8Xzv+I2pFPoHTbThNSVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1/WZhe1Ht+rh7cKNR+eb9m3ldvEyRW2n/kOXxbk97SUYOUcHL0dbAX7ttU3qU+Tt eh9fkMjDq9yl9E0lKOTs23WB28ZHtogBJF2JyX0aCnw7iSJsIuOAT/BdN7Xvj6lgQh GialgzMZHvKD+yhTbwMC97+J9h47W0v5/suGK/bk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Kees Cook , Wenwen Wang , stable , Greg Kroah-Hartman Subject: [PATCH 02/69] Revert "ACPI: custom_method: fix memory leaks" Date: Mon, 3 May 2021 13:56:29 +0200 Message-Id: <20210503115736.2104747-3-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503115736.2104747-1-gregkh@linuxfoundation.org> References: <20210503115736.2104747-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kees Cook This reverts commit 03d1571d9513369c17e6848476763ebbd10ec2cb. While /sys/kernel/debug/acpi/custom_method is already a privileged-only API providing proxied arbitrary write access to kernel memory[1][2], with existing race conditions[3] in buffer allocation and use that could lead to memory leaks and use-after-free conditions, the above commit appears to accidentally make the use-after-free conditions even easier to accomplish. ("buf" is a global variable and prior kfree()s would set buf back to NULL.) This entire interface needs to be reworked (if not entirely removed). [1] https://lore.kernel.org/lkml/20110222193250.GA23913@outflux.net/ [2] https://lore.kernel.org/lkml/201906221659.B618D83@keescook/ [3] https://lore.kernel.org/lkml/20170109231323.GA89642@beast/ Cc: Wenwen Wang Fixes: 03d1571d9513 ("ACPI: custom_method: fix memory leaks") Cc: stable Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/custom_method.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c index 443fdf62dd22..72469a49837d 100644 --- a/drivers/acpi/custom_method.c +++ b/drivers/acpi/custom_method.c @@ -53,10 +53,8 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf, if ((*ppos > max_size) || (*ppos + count > max_size) || (*ppos + count < count) || - (count > uncopied_bytes)) { - kfree(buf); + (count > uncopied_bytes)) return -EINVAL; - } if (copy_from_user(buf + (*ppos), user_buf, count)) { kfree(buf); @@ -76,7 +74,6 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf, add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE); } - kfree(buf); return count; } -- 2.31.1