Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1593964pxb; Thu, 4 Feb 2021 17:59:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJyU554wCPUOpJU6AdVO3wKkpO82MJvxorGWhKADpySMoKjKOPziwfZTEJpXwdXpZKY9BfUE X-Received: by 2002:a17:906:4955:: with SMTP id f21mr1867676ejt.477.1612490352217; Thu, 04 Feb 2021 17:59:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612490352; cv=none; d=google.com; s=arc-20160816; b=LXoXmxbty/wrLK885CTYDxKCj4dqN0gxIFmBaDu5EN1yLT08/ZZ8l8jtj222wvImWR t9zjceZFu/20W95vSTA3rbufPq2pkxmksOZRAnBWaMXDJRoSaA1b9ZeWKUgfsjSzcAhp SpjJxuC3QiSa0fPTtQDacBpdw4QAoxuFSsnuptaSD2I+65VbZigJU04Q/Fr0jWcuslAF kvz9K9TTZvaFgPqKX6lsqpkuSyzk2jvBhUqcvwS334YfvvQxOVfJodJVvQaQBaf1d5z7 M0sSCdmp80AMUTGkNf4WwbjIFmD7pQvymMgU8y2ITh8if/kk7O+Re9+liqWTIlXjMCeg C6nA== 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:cc:subject:date:to :from; bh=8yssV9m41XUwx6RfAScPnJ5J7vKPJBMFG9WHZGuHSKI=; b=J8AI+SAoHjjqgN/McZny0RNPoP3Lc/LOuVC0MB7r1WE5vOEJKhVN4JAsLQ+FGEqK72 KMY5kpkAuaRI1ag2BkHAHIOJgTgn8Ngu3LPowyxI28ouSPpnedbGKW+tizNzdAe+AvKK 4mGinLbVZ3xZcB4HqZ0g3JuvZigP2DZZcPx/Ey7kr1VFELe5UFT43nsaZ4XWlQAOXBLw g1kFxHZQCq5QND9Jb8s2vU3CCIVeCBHBqV4WhUoksJLns0Oc08Np95j5pp7yd9+ULJD3 Yzq1ehDs49XHmfLcd5QkR1LNsVIdFPLLw3FdH2dCb5UaFY2M1VO/RF/2s0PlMbYtF4hU s4Cg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si4694028ejg.426.2021.02.04.17.58.48; Thu, 04 Feb 2021 17:59:12 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232187AbhBEArj (ORCPT + 99 others); Thu, 4 Feb 2021 19:47:39 -0500 Received: from mx2.suse.de ([195.135.220.15]:38074 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232132AbhBEArf (ORCPT ); Thu, 4 Feb 2021 19:47:35 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 0509CB03B; Fri, 5 Feb 2021 00:46:54 +0000 (UTC) From: NeilBrown To: Andrew Morton , Alexander Viro , Ingo Molnar , Dave Hansen , Andy Lutomirski , Peter Zijlstra Date: Fri, 05 Feb 2021 11:36:30 +1100 Subject: [PATCH 2/3] x86: fix seq_file iteration for pat/memtype.c Cc: Xin Long , linux-kernel@vger.kernel.org Message-ID: <161248539022.21478.13874455485854739066.stgit@noble1> In-Reply-To: <161248518659.21478.2484341937387294998.stgit@noble1> References: <161248518659.21478.2484341937387294998.stgit@noble1> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memtype seq_file iterator allocates a buffer in the ->start and ->next functions and frees it in the ->show function. The preferred handling for such resources is to free them in the subsequent ->next or ->stop function call. Since Commit 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") there is no guarantee that ->show will be called after ->next, so this function can now leak memory. So move the freeing of the buffer to ->next and ->stop. Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") Cc: Xin Long Signed-off-by: NeilBrown --- arch/x86/mm/pat/memtype.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/pat/memtype.c b/arch/x86/mm/pat/memtype.c index 8f665c352bf0..ca311aaa67b8 100644 --- a/arch/x86/mm/pat/memtype.c +++ b/arch/x86/mm/pat/memtype.c @@ -1164,12 +1164,14 @@ static void *memtype_seq_start(struct seq_file *seq, loff_t *pos) static void *memtype_seq_next(struct seq_file *seq, void *v, loff_t *pos) { + kfree(v); ++*pos; return memtype_get_idx(*pos); } static void memtype_seq_stop(struct seq_file *seq, void *v) { + kfree(v); } static int memtype_seq_show(struct seq_file *seq, void *v) @@ -1181,8 +1183,6 @@ static int memtype_seq_show(struct seq_file *seq, void *v) entry_print->end, cattr_name(entry_print->type)); - kfree(entry_print); - return 0; }