Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2481418pxj; Mon, 10 May 2021 04:08:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxshvvA23Z8OREtkEnOyuENRRfEdV1LxWsgeWtVrGYC+woOo0yo9Qyp91bklpR0GmO7MITh X-Received: by 2002:aa7:d806:: with SMTP id v6mr29058060edq.309.1620644926625; Mon, 10 May 2021 04:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620644926; cv=none; d=google.com; s=arc-20160816; b=JawA1NyXvtaxKq0Ej0tR3bJmghrPOyse0fX+XR+ObfTQ+FPfGm3MFMRGu9jn1kIchB gsaRv3ZyYUU6mpZltsJeOWYPWWcaWrd+CRniuxQYejey+ahgaExkkDJOaE5ZzB8TTOS4 ZVVGoUJICUWHkugZZLNUBz0YkKVjACWjN5CRXHJC/0KgichBZuUKmC8FNfvVIkIEYwl2 sIE5GOUA8YHurR1gpWGqz2WU3quDKeO+DTpKPx5HmVuaPLw9rS3jTIA3zCKSrkvRPK5R KykCh3tNPRL/wf2m96rtZU+ZrEx1/n9ZneLhxqlSJQyyxFkH1fe8/GSo1xYyJ/pnHb4P nb4Q== 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=qHT6ZmxALa4UvcPPa5qqG6rvRom+fXV+a5BcVmlGRnU=; b=arcwo+JT8Fc8+lGqy1H/t7VlBirsTtXWJgY65LSOWPDn7NZIr+5fk79cW8/NE240kC JpvVj+KkvPQqytOQP3mV9z+6BHkLAMNM/hCW1Ui20BXAOKBVRLmZAlQppw145hKPuFM+ 2pXXV5VveaLnl27BXU4MnCMtT+GiQ9s8JJc1IucuIPoVltM6ZimCQWUy6rgC4laWV9Ed QZvDVH3fgbbtDNRu3HS0rN1FCCyzNY8LIWhqND/MXPFr3/SjQC5Q0FOZOR/svuH4MoRa 3dNHMWpZ5PesH36E0QaFSAnDo7Pbg7/ckQ5w9azagV4n72lGGTFAziFjHp48tUoqwWdI l9lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ePcUY0eb; 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 c8si5588528edu.520.2021.05.10.04.08.19; Mon, 10 May 2021 04:08:46 -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=ePcUY0eb; 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 S233427AbhEJK7H (ORCPT + 99 others); Mon, 10 May 2021 06:59:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:57152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbhEJKnI (ORCPT ); Mon, 10 May 2021 06:43:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3D2961983; Mon, 10 May 2021 10:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642773; bh=xZJ482XOAPo4NHz/gYmgW/ROsIxqwtHKbtewnL8D5nY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ePcUY0eblEapxHBd3DAL4N1D0UTybsJjmLP0Tu1u/z73LOTWQcvraVhrtltqLH/l7 HsK8rhkSHSxh6m98PVwdgGGq+Po/eng8kJfnQYNpFpZTrQ5iigcOLolFg7QkLUPVB2 C5bMbDBKZYDDpNtyZWXUDjQxx1auicHOw/kdHp4E= 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 5.10 010/299] ACPI: custom_method: fix potential use-after-free issue Date: Mon, 10 May 2021 12:16:47 +0200 Message-Id: <20210510102005.174367487@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 @@ -55,6 +55,7 @@ static ssize_t cm_write(struct file *fil (*ppos + count < count) || (count > uncopied_bytes)) { kfree(buf); + buf = NULL; return -EINVAL; } @@ -76,7 +77,6 @@ static ssize_t cm_write(struct file *fil add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE); } - kfree(buf); return count; }