From patchwork Mon May 3 11:56:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 431133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41C7CC433ED for ; Mon, 3 May 2021 12:00:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BB6A6137D for ; Mon, 3 May 2021 12:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233787AbhECMBi (ORCPT ); Mon, 3 May 2021 08:01:38 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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; }