Skip to content

Commit 5674609

Browse files
committed
pstore: Change kmsg_bytes storage size to u32
The types around kmsg_bytes were inconsistent. The global was unsigned long, the argument to pstore_set_kmsg_bytes() was int, and the filesystem option was u32. Given other internal limits, there's not much sense in making a single pstore record larger than INT_MAX and it can't be negative, so use u32 everywhere. Additionally, use READ/WRITE_ONCE and a local variable in pstore_dump() to avoid kmsg_bytes changing during a dump. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent a64dcfb commit 5674609

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

fs/pstore/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static void parse_options(char *options)
265265
static int pstore_show_options(struct seq_file *m, struct dentry *root)
266266
{
267267
if (kmsg_bytes != CONFIG_PSTORE_DEFAULT_KMSG_BYTES)
268-
seq_printf(m, ",kmsg_bytes=%lu", kmsg_bytes);
268+
seq_printf(m, ",kmsg_bytes=%u", kmsg_bytes);
269269
return 0;
270270
}
271271

fs/pstore/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <linux/time.h>
77
#include <linux/pstore.h>
88

9-
extern unsigned long kmsg_bytes;
9+
extern unsigned int kmsg_bytes;
1010

1111
#ifdef CONFIG_PSTORE_FTRACE
1212
extern void pstore_register_ftrace(void);
@@ -35,7 +35,7 @@ static inline void pstore_unregister_pmsg(void) {}
3535

3636
extern struct pstore_info *psinfo;
3737

38-
extern void pstore_set_kmsg_bytes(int);
38+
extern void pstore_set_kmsg_bytes(unsigned int bytes);
3939
extern void pstore_get_records(int);
4040
extern void pstore_get_backend_records(struct pstore_info *psi,
4141
struct dentry *root, int quiet);

fs/pstore/platform.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ module_param(compress, charp, 0444);
9292
MODULE_PARM_DESC(compress, "compression to use");
9393

9494
/* How much of the kernel log to snapshot */
95-
unsigned long kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
96-
module_param(kmsg_bytes, ulong, 0444);
95+
unsigned int kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
96+
module_param(kmsg_bytes, uint, 0444);
9797
MODULE_PARM_DESC(kmsg_bytes, "amount of kernel log to snapshot (in bytes)");
9898

9999
static void *compress_workspace;
@@ -107,9 +107,9 @@ static void *compress_workspace;
107107
static char *big_oops_buf;
108108
static size_t max_compressed_size;
109109

110-
void pstore_set_kmsg_bytes(int bytes)
110+
void pstore_set_kmsg_bytes(unsigned int bytes)
111111
{
112-
kmsg_bytes = bytes;
112+
WRITE_ONCE(kmsg_bytes, bytes);
113113
}
114114

115115
/* Tag each group of saved records with a sequence number */
@@ -278,6 +278,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
278278
struct kmsg_dump_detail *detail)
279279
{
280280
struct kmsg_dump_iter iter;
281+
unsigned int remaining = READ_ONCE(kmsg_bytes);
281282
unsigned long total = 0;
282283
const char *why;
283284
unsigned int part = 1;
@@ -300,7 +301,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
300301
kmsg_dump_rewind(&iter);
301302

302303
oopscount++;
303-
while (total < kmsg_bytes) {
304+
while (total < remaining) {
304305
char *dst;
305306
size_t dst_size;
306307
int header_size;

0 commit comments

Comments
 (0)