Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp411244pxj; Thu, 20 May 2021 12:11:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9/uoyq3ZuRgqHMGvs+wbAA3tebU67ep+QySVqyoUvX/Bf7OgyEgsM1WmNqiF5fc9szOO4 X-Received: by 2002:a05:6402:696:: with SMTP id f22mr6436559edy.131.1621537887589; Thu, 20 May 2021 12:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621537887; cv=none; d=google.com; s=arc-20160816; b=KRaqCpWYUHHH5pOJaTC5ecCWIBV6Q1T1mEvw7e0gYvZDFZXSMVwe10yxCXCrVHVZIb mB66kl5DjsH5cukT0/Hu0i8R88YkBuj4e2juVwZrs1vmNjGVr4+u0nflgvsovveHclu0 HS4zBvXikszFJHSw9tuwSXQINAYoSDqHatDUSm2uTiLUkzwacMPNTKCDa4wASW+k74ho VDM3EGvxz5viCjgdTTyDpVrPkTK6Sby07MVcHFsj4+4/CVxL9yQEUkkIK26BvzRBgPw8 gFnzl5R4W2YdKpD7gx+4Z26aurwXMK5fe7AuF6nMBdBArxoWIsAZlEUM1Xgd+VaSd4cD wtbA== 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=TwNlg+CvbdoVpRsXIYc9Uwt12l49Lgq+PokQkcLTstQ=; b=KHFT3hSYpaEadTF0wYrQuKM9LSXwJ+WF6qFVm/Fy+O3TtqSWrt5kYZORlKDeD2qwJD wc6TSQz7JHvYprlkIKEdcZaNBdIdFxhB/R2MKz03ip9EHRtY4KsM4lSKHDnv/7X4hroq xUMBq8uBKEpU7VRJLIJd7U4+Hlwhyste3z1LO4Xaz52LPNu8d2u1S2/pkrO4oKeo78/x rM85fBqh5UmGLVrk/7Lnu+wRQhHhHQLuaCSw9+DelU9dqR0CDWoi0+O14RBJCxviLdpV WAMlrwpK5RK2x1HibIcfYgs8Zscc1Tt4UBmfX8fA6C0n72Kub0/dzZf4aKSo658dGM1C MCzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cAc26GM3; 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 h2si3343654ejf.704.2021.05.20.12.11.02; Thu, 20 May 2021 12:11:27 -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=cAc26GM3; 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 S236510AbhETK2f (ORCPT + 99 others); Thu, 20 May 2021 06:28:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:48156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236509AbhETKP2 (ORCPT ); Thu, 20 May 2021 06:15:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 98ACA6199C; Thu, 20 May 2021 09:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503948; bh=AQCgiZQKfDgZW64XvcUOoHXZf+lYBeOXQbgpMYOkqTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cAc26GM3rLlFh4EpZc+kJowf/bLtJI9HwKOcGicIGawmU/1N5gFzRfRgxsaepgaM1 zE0rGzYwmqlp/X+UHl5cxj2AyvOa9QPfiHXRV085ZazeKCYyraRldynmH30SbYYfMD gXpSu4E1wmspK0UzD06VsXno8C+HpvnV7AzgTRCo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Langsdorf , "Rafael J. Wysocki" Subject: [PATCH 4.14 018/323] ACPI: custom_method: fix potential use-after-free issue Date: Thu, 20 May 2021 11:18:30 +0200 Message-Id: <20210520092120.739463648@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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: Mark Langsdorf commit e483bb9a991bdae29a0caa4b3a6d002c968f94aa upstream. In cm_write(), buf is always freed when reaching the end of the function. If the requested count is less than table.length, the allocated buffer will be freed but subsequent calls to cm_write() will still try to access it. Remove the unconditional kfree(buf) at the end of the function and set the buf to NULL in the -EINVAL error path to match the rest of function. Fixes: 03d1571d9513 ("ACPI: custom_method: fix memory leaks") Signed-off-by: Mark Langsdorf Cc: 5.4+ # 5.4+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/custom_method.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/acpi/custom_method.c +++ b/drivers/acpi/custom_method.c @@ -50,6 +50,7 @@ static ssize_t cm_write(struct file *fil (*ppos + count < count) || (count > uncopied_bytes)) { kfree(buf); + buf = NULL; return -EINVAL; } @@ -71,7 +72,6 @@ static ssize_t cm_write(struct file *fil add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE); } - kfree(buf); return count; }