Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2472694pxj; Mon, 10 May 2021 03:57:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKohWrYik19+ZHfCcrVYfNqk6rX+yJIbxbmIYV6Zkb8SfQV9Vnzyow0hEhYJYg8dB4Q7Nl X-Received: by 2002:a6b:14d2:: with SMTP id 201mr17422849iou.15.1620644271278; Mon, 10 May 2021 03:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620644271; cv=none; d=google.com; s=arc-20160816; b=PgkHJK9DXWJyweUlSFBa4iKQhvBoaXH38gJp4cIKmRjT4C3qFq8ErW9HdxogCROiL0 aEkeZaG4nUp1kHNM4egE5f1/q7OE6CE6H3UJp4JofssV1VipxkuVuFXiTQWa8tePFMvG yu5th+iebXADVUPKmUwMTjIjVduUu7nr0SEJWwqEROb80oS6mkb9ODXwpNpFzEvepPoj uEz5iPF2NEnasOYTI7m0h58piY4aLyp9ENMx74yPgYoS6SHkDMHkqbS9lyW3oQfjwFga wQOBgGfx8Oz+ZAJ2pWoHeqaUAFVpvw1f5/XpILhLZCCf9GwYcLp5ryIFcTETnbJDYz4e JRtw== 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=tz83uL+ijuB5xCC+U4l5jtjuDKmbq8NAAekRG+OzkkI=; b=QoGhfZQplFv6XOja/YHmt4BDKtcH1q12Y2JABfCWY6iGkKeY+7JofB/iV+cKoqH93t l+MveqBnPK4HvHrUIwNsfTQQyR11QroP0aDgYATO89FlsMyFp5S3fKkrNbEr7wzbZD63 806ZZpjConYs6Su1xb1e96R5gUggsWuoxGdVmZMfbqjZ5ObpJxsET3k7IdVV4WerR8pL U7+eJLUOx3tbSMpxCGfhePOiGGPVb4v7a9i4GJnyghUanKhIJK1xMKhqwTrgX2NmXnDN 5hMJBBvnQyPT9adMnDu6UQu/KxobC6o+M6mhwiua+L/+4uAO6iBuuVVLCBTQu+SAoA1b ENzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=H8TAHwP6; 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 s4si18136422ilv.29.2021.05.10.03.57.38; Mon, 10 May 2021 03:57:51 -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=H8TAHwP6; 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 S233251AbhEJKyc (ORCPT + 99 others); Mon, 10 May 2021 06:54:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57348 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbhEJKnO (ORCPT ); Mon, 10 May 2021 06:43:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6300161982; Mon, 10 May 2021 10:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620642775; bh=HJQU5DyvW9xduhipoOniHRMWuWAwWg7D4AkVdwbJluA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H8TAHwP6GDYIkoeE9ey7TKvYNvzWL/fz3p6KnHlhbzOc54DNE5OV0AVOvJOKHDA4g Nx7Xij2SwL0/09Vw6daHEedZfBpA2iG+ciSkG4JFAaJ6uQD0rtRzqD0MfQiQryo6fb ycTNPrJbJflKm+enTAxRCY3+pQFlaVg4fE/849yM= 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 011/299] ACPI: custom_method: fix a possible memory leak Date: Mon, 10 May 2021 12:16:48 +0200 Message-Id: <20210510102005.212191743@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 1cfd8956437f842836e8a066b40d1ec2fc01f13e upstream. In cm_write(), if the 'buf' is allocated memory but not fully consumed, it is possible to reallocate the buffer without freeing it by passing '*ppos' as 0 on a subsequent call. Add an explicit kfree() before kzalloc() to prevent the possible memory leak. Fixes: 526b4af47f44 ("ACPI: Split out custom_method functionality into an own driver") 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, 2 insertions(+) --- a/drivers/acpi/custom_method.c +++ b/drivers/acpi/custom_method.c @@ -42,6 +42,8 @@ static ssize_t cm_write(struct file *fil sizeof(struct acpi_table_header))) return -EFAULT; uncopied_bytes = max_size = table.length; + /* make sure the buf is not allocated */ + kfree(buf); buf = kzalloc(max_size, GFP_KERNEL); if (!buf) return -ENOMEM;