Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp404346pxj; Thu, 20 May 2021 12:02:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDYcmUs5FuMZ1VnryJuXg2/UPnXKd3PmjwLkcciUYEkyCd25JOTaz/f7U5zqFqhVV2mWPF X-Received: by 2002:a05:6e02:1d1a:: with SMTP id i26mr7576847ila.180.1621537347884; Thu, 20 May 2021 12:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621537347; cv=none; d=google.com; s=arc-20160816; b=g9Gwfeymv9Mi4zZPxAPwFL0SRStwnH47kym62mdpwfS5YZ0h7rQfKADm7Uuo+ds/zy 93W/i4bupq8oJHHkkzJi23pKHG2Le4cmWPic69eMZ82yPPTjJPpE9pjyFgmqRRlK1FUs O5cH5ddURYB/Erle5WlkE4hW8pCvmYMPRJv8DA5sIBlWW0ssIKJGtY+qAsuONISNqgsd CB3xfhV5SbyKvKirkbPx9LQuVrV99G/zsi0k3hlO2EnQNQyPg25zT2Didx76rNoVm4OI MTtDoTRJJFMezG1zyFV2YYT4bESpDCL33KcqzKOmJCRqqUUKdZS3sSO3jx9oa5yH44kJ zndQ== 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=MoNp0f2OGO0EbuBkL8Bpsvb+Rvpv7NVgIfdTuclMB9ymNi/hLveHiXPKIi+PPdY4we rgQJxIy+Wyb+XhzTLlF2QFkYo3nlohu8Z23pu/0p80xHZoILwomPvnN2JB8LaqY71Yjm vUv/lnikxHGfv2SmYb4uNuxYiVa1kQqhr8p0m0RTcMfIOW7VfuiSAaAhIbtZP3MBdP6Q 0NKeFLpq+nriQJzCF299+mJruWpHUI4lK4M0dv8NIidlk8N9nT0/8ikOfws0kUxiCIln xF8Drs4Tts8/Ue4wj8ckubHLjBGvdU1C5UkpHEkBUq24DAaprXj3eqh5odhb7AD2MYsz RZ+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q8tmpJ8E; 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 t19si2754807iog.66.2021.05.20.12.02.14; Thu, 20 May 2021 12:02: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=q8tmpJ8E; 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 S237176AbhETK3m (ORCPT + 99 others); Thu, 20 May 2021 06:29:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:47658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235819AbhETKRR (ORCPT ); Thu, 20 May 2021 06:17:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D47D1619A0; Thu, 20 May 2021 09:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503972; bh=ElMWXytHLhIqi64Gk7kpZGsahtsBL1G92TPQA90NMtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q8tmpJ8Eb5D5MCQzFJnInXPWQbiGUZbvMm16sZgJEb7iX6Bpd3t45XMuzckP/9Ht2 u9wPQDkyP7dPmQoiSobYRGJyCw9QiUekKQ3p742Isxm56HbL6r9UTUkHnsYSSn64E0 b30nLyB1Uz36V/5b69fSXUPHBcB5IYbxfJfnZuzA= 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 019/323] ACPI: custom_method: fix a possible memory leak Date: Thu, 20 May 2021 11:18:31 +0200 Message-Id: <20210520092120.774526464@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 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;