Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp543262pxj; Thu, 20 May 2021 15:48:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuGp4Uuby36cgpgJsKc+61V0YmpbSDdLfDAj/CXz/xTDO3DK0Mh/NC3nkYsYCiqFZrkiLW X-Received: by 2002:a17:906:ccde:: with SMTP id ot30mr7099998ejb.353.1621550882029; Thu, 20 May 2021 15:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621550882; cv=none; d=google.com; s=arc-20160816; b=P/UvbCxIZ4Z5gtwj9WKTwbPCGy+GhPwBXr3y0BvQC8tPTeaNGv6OFCmAZWLbx1l6Bv kIxjhPQGF+3Ru5b34fspddgXmrSmRSUphFXHfpOIxhqn4PPrluzOlS1l/ayYfBxuTJin NNQ5G1xFsHdUcDGhXWL4OKV6QuxvjLhFxk1+62b97HZt4PeNbAO6QN9IQX+wzyBvhbsp fO5BPa7q9agcnfjn6PlHTSL5A+1rC/cVL75xwrhB0Yg2qLV0Q0IUak0/oe5BKUl8gHAc cn8ZkqIBZxrTUiIsgY4/s1nyPbInlbZSruWesTV22p+rzUB0kqApcwS+KCJFRyPgVmbo tXvg== 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=uax8vHvTjJKaiR8D5he9i5muWgxIInLoNLIFPI3tQhE=; b=PATuavhT+gHb5Edg/9HNjvIqNo9bE8aRTUgqC26YuYJvTOVft29BOhwJd6qt0TpwJg BpLU2cAwLk46MM2fVg1uaTTHuGnfml/eCOflB6ubSBsordr8F2JiRPvqBOAkSxITdY2p Rl4q6rdadzfSa/kHRuKt26iw69X4KYMVg3ffvtolyfEP6hjqyhu9DtvMg8tEk0h83a7r CwiUcDYi7yKq/1RPgbs8bvTLKzBsRdOn3VfV1nyxVV7W2b3pk15qkAvV0UuSKF504rOZ Lo8oFQlUDHn+0iRRs8b/S/pHkWAnYb5/m41reA6v4fi64E9PA1Ko2THO7HU2TdkFIYjG DR3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Z4+JYn42; 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 i8si757350ejj.74.2021.05.20.15.47.38; Thu, 20 May 2021 15:48:02 -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=Z4+JYn42; 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 S239666AbhETLGn (ORCPT + 99 others); Thu, 20 May 2021 07:06:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237208AbhETKr2 (ORCPT ); Thu, 20 May 2021 06:47:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8ED6161CAF; Thu, 20 May 2021 09:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504697; bh=ElMWXytHLhIqi64Gk7kpZGsahtsBL1G92TPQA90NMtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4+JYn42S9Yiz1UR+OFR6W6SZOM0xGruLNbW+cYo2fFgP7/Qd6WGZgB80lkUPuQFA le/SurN0n+7frz+eH2pspm2CMeHk9Q9l1J3yXnpq//EB0ENgiZDT30KkLZYoKSevs9 b27Jri5ll9cviDEUbUllfWTWIFSy1MrvNsQrL5E8= 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.9 009/240] ACPI: custom_method: fix a possible memory leak Date: Thu, 20 May 2021 11:20:01 +0200 Message-Id: <20210520092108.917841282@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 @@ -37,6 +37,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;