Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp609592pxj; Thu, 20 May 2021 17:46:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJjN3aTSWAMq6S1F3/5/Cc+g7s/3Fpcx25XnjRoe1/Qe6zM0ASvJ/D1tbAos6CFKU3RJAK X-Received: by 2002:a6b:4f17:: with SMTP id d23mr8046006iob.91.1621557996998; Thu, 20 May 2021 17:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621557996; cv=none; d=google.com; s=arc-20160816; b=GIKa5tEI7Kt1vEZqreh9Efjj8d4/ubwzeMJTX6+0ZWXk/DoqcyaQ3r00viJxwMTcJH bjNgsR93rs75Rr++ZwW1PZVBuYzLnuY+v8oGeHkJjJlxeimfUPxoiq9gEKG60dtWFLj/ FCnggK4ns2QEk8QjXVKkt2vlePW7Mn8OxNHZUNxEW3qNKBswuEduv7XpW1QVxYiXQxq7 Iz+pmZu7dRS5+JScFm2gF4HY3QP2wJ3AdAyDKi2suSBLmbDh2MbhI4hXNPxBU5niHlCv rbQk70gZ5Uj2lPpk5PgOZhpT4M3OKog3iIQEokh8Ss5zknVUHDpUNX+rngA2uRm3tIFO u7nQ== 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=q2uNCqdcA7sz1gfL51uY+jTJLo4bZWVp7pANXBtg0lwzJHRbAdyhQJjDcSjKmOlGek 7FqzkpzJNG/pXBj2Fnc3w0Rz+ZOUAK6wLKNbrU7ZBU7GWYe0LOISkOrht2CAMor+Zo85 9keSmnWDKL4UO5VNa+S8IIrMGB9Z4rwN25dh63rQNycmk0JsKlpjKlViWOOY8/FrrSSE N9EttMCqdKayJQ5+LUqVzZjUvkU0FeyFBC9D4vCnDIlHp5gffS3ygffNDYyqyiLphQn3 85x7aj95OzsvH4ey4Fm5xPuCjlQXM5PebgscF/O5O6oGr6KA3WEmlxYstiC8sG8avJAF qPAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZqxGifia; 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 r4si3812080iov.63.2021.05.20.17.46.23; Thu, 20 May 2021 17:46:36 -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=ZqxGifia; 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 S240462AbhETLa2 (ORCPT + 99 others); Thu, 20 May 2021 07:30:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:58196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239662AbhETLKh (ORCPT ); Thu, 20 May 2021 07:10:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46ACA61D48; Thu, 20 May 2021 10:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505229; bh=AQCgiZQKfDgZW64XvcUOoHXZf+lYBeOXQbgpMYOkqTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqxGifia04oz5TDNsNOsMCl9hpZOlUQNMTR/uEgPQ1CfFzEy7E6thm7E+dCNSHn5T rYZk+rw1E6P3Eq07KYCrO75qtzZsDh7UBI8LWvZvPJvemVf2ptkPPwaCdotSSgVyV+ r1pDi5D9CqYbcmfXZy0kKM+AQXVxTd+FS1+av6H0= 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.4 009/190] ACPI: custom_method: fix potential use-after-free issue Date: Thu, 20 May 2021 11:21:13 +0200 Message-Id: <20210520092102.487669532@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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; }