Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3572301pxb; Mon, 1 Mar 2021 13:45:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoLHoKJs9If5i0OkLKcNCoWVvDCPpUWFzBCday035+LKxWU8zhuTjg2PGJO7WvC+xeY5QJ X-Received: by 2002:a17:907:76bb:: with SMTP id jw27mr17641234ejc.366.1614635140591; Mon, 01 Mar 2021 13:45:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614635140; cv=none; d=google.com; s=arc-20160816; b=VOIZqGEfv0hpG/tLk0hAQDerc7PJJT0tTVYR0X7hE8F83STJCJC8kpU0aMqB1g6nhH REPLZjcC16+kK2X+2k6RzwvZc7JL2dH8dYAQWBNPAwvtrJXY+xS1tJzuruDaaAMKLjj1 L4Z7GqSCNTVECWjJkkI+JIrC6Qkpm+YXEnNJ/01OBHaRBKRO95YDuBowS68OhcYaiaWq 4A4z3wcAIQ8IQa/cRd2oHGPrvbvaQFd9KLpvzXz69YJKBmQr5WtL08+hC8Fan/ltjrqh t0y08Rp0Tyg4k267rqQDvC5wJvc3PmpDK7e3rvEUhGX/10mzSrDqsi72k6JStnjjLQ5u ZVAg== 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=gVFLIJ+kBeNx/uy37efXJAtCeBwdYXuqK0R0wAKu3p0=; b=vfBboI8nA/tpTQZ4ZJfFQ58e37srkLF5idMB/YE/Nl6n0CVMoFOk1ZbJSD/HdCuHl+ ggeqOyCxKO8FmZ+hdF91bWtE639BXZoNFEb0Wko8WqkSiIXY0sIdwQ/RboCxCZ+lIhQD dTfiZTCyeBmD84+MoJs+0lVLSkGWKfMiZbknJJdaYizrmKINV0LgJEZ8Scjd6OTmadv+ 8iR83LG29OfIt8dfN4qb3slzPLyfEc6Zp3MaBGNNlHKLOMKfgowVg7MxI5dAgdpkNoGz ZMR3OL70CGkAtVpr7olbTqgkDIgUfOcgB1ykYCEni9BjtdRX2VIDm9Nqy6h0X3pL5Ddc oDEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D4UqD4tB; 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 gr12si7799026ejb.306.2021.03.01.13.45.18; Mon, 01 Mar 2021 13:45:40 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D4UqD4tB; 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 S241434AbhCAVmw (ORCPT + 99 others); Mon, 1 Mar 2021 16:42:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:37368 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237334AbhCARSx (ORCPT ); Mon, 1 Mar 2021 12:18:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1556F65056; Mon, 1 Mar 2021 16:47:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617250; bh=STPFzSHHWTJjMcsWb2LqTYBn4U3MXowVAnweTf/CMvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D4UqD4tBgaeqgsT92+INt3fZNv27OoU6JJT+so4Lq8xVut3yajfGN5WkNhwZn08Q0 +12Os2wpbk0Z4gIhh1WwPfS+2N5KEm4l7DLUXlocxPcBlw/6W0Z09Hs7qRMpiVFvak 5uUaRSWFmBZ7Ok7pEMKcLQpkjaghS5k01/YdEVnk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Xin Long , Alexander Viro , Andy Lutomirski , Dave Hansen , "David S. Miller" , Ingo Molnar , Jonathan Corbet , Marcelo Ricardo Leitner , Neil Horman , Peter Zijlstra , Vlad Yasevich , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 220/247] x86: fix seq_file iteration for pat/memtype.c Date: Mon, 1 Mar 2021 17:14:00 +0100 Message-Id: <20210301161042.449644211@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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: NeilBrown commit 3d2fc4c082448e9c05792f9b2a11c1d5db408b85 upstream. 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. Link: https://lkml.kernel.org/r/161248539022.21478.13874455485854739066.stgit@noble1 Fixes: 1f4aace60b0e ("fs/seq_file.c: simplify seq_file iteration code and interface") Signed-off-by: NeilBrown Cc: Xin Long Cc: Alexander Viro Cc: Andy Lutomirski Cc: Dave Hansen Cc: "David S. Miller" Cc: Ingo Molnar Cc: Jonathan Corbet Cc: Marcelo Ricardo Leitner Cc: Neil Horman Cc: Peter Zijlstra Cc: Vlad Yasevich Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/x86/mm/pat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/arch/x86/mm/pat.c +++ b/arch/x86/mm/pat.c @@ -1131,12 +1131,14 @@ static void *memtype_seq_start(struct se 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) @@ -1145,7 +1147,6 @@ static int memtype_seq_show(struct seq_f seq_printf(seq, "%s @ 0x%Lx-0x%Lx\n", cattr_name(print_entry->type), print_entry->start, print_entry->end); - kfree(print_entry); return 0; }