Skip to content

Commit e50e042

Browse files
tehcasterharshimogalapalli
authored andcommitted
mm, slab: cleanup slab_bug() parameters
[ Upstream commit 4b183dd ] slab_err() has variadic printf arguments but instead of passing them to slab_bug() it does vsnprintf() to a buffer and passes %s, buf. To allow passing them directly, turn slab_bug() to __slab_bug() with a va_list parameter, and slab_bug() a wrapper with fmt, ... parameters. Then slab_err() can call __slab_bug() without the intermediate buffer. Also constify fmt everywhere, which also simplifies object_err()'s call to slab_bug(). Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Harry Yoo <[email protected]> Stable-dep-of: b4efccec8d06 ("mm/slub: avoid accessing metadata when pointer is invalid in object_err()") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 9cd3206f0126d9e1079fb8817629c16c0c6293fd) Signed-off-by: Harshit Mogalapalli <[email protected]>
1 parent ea0bb07 commit e50e042

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

mm/slub.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,12 +1031,12 @@ void skip_orig_size_check(struct kmem_cache *s, const void *object)
10311031
set_orig_size(s, (void *)object, s->object_size);
10321032
}
10331033

1034-
static void slab_bug(struct kmem_cache *s, char *fmt, ...)
1034+
static void __slab_bug(struct kmem_cache *s, const char *fmt, va_list argsp)
10351035
{
10361036
struct va_format vaf;
10371037
va_list args;
10381038

1039-
va_start(args, fmt);
1039+
va_copy(args, argsp);
10401040
vaf.fmt = fmt;
10411041
vaf.va = &args;
10421042
pr_err("=============================================================================\n");
@@ -1045,8 +1045,17 @@ static void slab_bug(struct kmem_cache *s, char *fmt, ...)
10451045
va_end(args);
10461046
}
10471047

1048+
static void slab_bug(struct kmem_cache *s, const char *fmt, ...)
1049+
{
1050+
va_list args;
1051+
1052+
va_start(args, fmt);
1053+
__slab_bug(s, fmt, args);
1054+
va_end(args);
1055+
}
1056+
10481057
__printf(2, 3)
1049-
static void slab_fix(struct kmem_cache *s, char *fmt, ...)
1058+
static void slab_fix(struct kmem_cache *s, const char *fmt, ...)
10501059
{
10511060
struct va_format vaf;
10521061
va_list args;
@@ -1102,12 +1111,12 @@ static void print_trailer(struct kmem_cache *s, struct slab *slab, u8 *p)
11021111
}
11031112

11041113
static void object_err(struct kmem_cache *s, struct slab *slab,
1105-
u8 *object, char *reason)
1114+
u8 *object, const char *reason)
11061115
{
11071116
if (slab_add_kunit_errors())
11081117
return;
11091118

1110-
slab_bug(s, "%s", reason);
1119+
slab_bug(s, reason);
11111120
print_trailer(s, slab, object);
11121121
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
11131122

@@ -1143,15 +1152,14 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct slab *slab,
11431152
const char *fmt, ...)
11441153
{
11451154
va_list args;
1146-
char buf[100];
11471155

11481156
if (slab_add_kunit_errors())
11491157
return;
11501158

11511159
va_start(args, fmt);
1152-
vsnprintf(buf, sizeof(buf), fmt, args);
1160+
__slab_bug(s, fmt, args);
11531161
va_end(args);
1154-
slab_bug(s, "%s", buf);
1162+
11551163
__slab_err(slab);
11561164
}
11571165

@@ -1189,7 +1197,7 @@ static void init_object(struct kmem_cache *s, void *object, u8 val)
11891197
s->inuse - poison_size);
11901198
}
11911199

1192-
static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
1200+
static void restore_bytes(struct kmem_cache *s, const char *message, u8 data,
11931201
void *from, void *to)
11941202
{
11951203
slab_fix(s, "Restoring %s 0x%p-0x%p=0x%x", message, from, to - 1, data);
@@ -1204,7 +1212,7 @@ static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
12041212

12051213
static pad_check_attributes int
12061214
check_bytes_and_report(struct kmem_cache *s, struct slab *slab,
1207-
u8 *object, char *what, u8 *start, unsigned int value,
1215+
u8 *object, const char *what, u8 *start, unsigned int value,
12081216
unsigned int bytes, bool slab_obj_print)
12091217
{
12101218
u8 *fault;

0 commit comments

Comments
 (0)