Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

x86: fix seq_file iteration for pat/memtype.c

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 <neilb@suse.de>
Cc: Xin Long <lucien.xin@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Vlad Yasevich <vyasevich@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

NeilBrown and committed by
Linus Torvalds
3d2fc4c0 b3656d82

+2 -2
+2 -2
arch/x86/mm/pat/memtype.c
··· 1164 1164 1165 1165 static void *memtype_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1166 1166 { 1167 + kfree(v); 1167 1168 ++*pos; 1168 1169 return memtype_get_idx(*pos); 1169 1170 } 1170 1171 1171 1172 static void memtype_seq_stop(struct seq_file *seq, void *v) 1172 1173 { 1174 + kfree(v); 1173 1175 } 1174 1176 1175 1177 static int memtype_seq_show(struct seq_file *seq, void *v) ··· 1182 1180 entry_print->start, 1183 1181 entry_print->end, 1184 1182 cattr_name(entry_print->type)); 1185 - 1186 - kfree(entry_print); 1187 1183 1188 1184 return 0; 1189 1185 }