Skip to content

Commit 2eefec3

Browse files
tehcasteropsiff
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)
1 parent 3e659d9 commit 2eefec3

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
@@ -1027,12 +1027,12 @@ void skip_orig_size_check(struct kmem_cache *s, const void *object)
10271027
set_orig_size(s, (void *)object, s->object_size);
10281028
}
10291029

1030-
static void slab_bug(struct kmem_cache *s, char *fmt, ...)
1030+
static void __slab_bug(struct kmem_cache *s, const char *fmt, va_list argsp)
10311031
{
10321032
struct va_format vaf;
10331033
va_list args;
10341034

1035-
va_start(args, fmt);
1035+
va_copy(args, argsp);
10361036
vaf.fmt = fmt;
10371037
vaf.va = &args;
10381038
pr_err("=============================================================================\n");
@@ -1041,8 +1041,17 @@ static void slab_bug(struct kmem_cache *s, char *fmt, ...)
10411041
va_end(args);
10421042
}
10431043

1044+
static void slab_bug(struct kmem_cache *s, const char *fmt, ...)
1045+
{
1046+
va_list args;
1047+
1048+
va_start(args, fmt);
1049+
__slab_bug(s, fmt, args);
1050+
va_end(args);
1051+
}
1052+
10441053
__printf(2, 3)
1045-
static void slab_fix(struct kmem_cache *s, char *fmt, ...)
1054+
static void slab_fix(struct kmem_cache *s, const char *fmt, ...)
10461055
{
10471056
struct va_format vaf;
10481057
va_list args;
@@ -1098,12 +1107,12 @@ static void print_trailer(struct kmem_cache *s, struct slab *slab, u8 *p)
10981107
}
10991108

11001109
static void object_err(struct kmem_cache *s, struct slab *slab,
1101-
u8 *object, char *reason)
1110+
u8 *object, const char *reason)
11021111
{
11031112
if (slab_add_kunit_errors())
11041113
return;
11051114

1106-
slab_bug(s, "%s", reason);
1115+
slab_bug(s, reason);
11071116
print_trailer(s, slab, object);
11081117
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
11091118

@@ -1139,15 +1148,14 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct slab *slab,
11391148
const char *fmt, ...)
11401149
{
11411150
va_list args;
1142-
char buf[100];
11431151

11441152
if (slab_add_kunit_errors())
11451153
return;
11461154

11471155
va_start(args, fmt);
1148-
vsnprintf(buf, sizeof(buf), fmt, args);
1156+
__slab_bug(s, fmt, args);
11491157
va_end(args);
1150-
slab_bug(s, "%s", buf);
1158+
11511159
__slab_err(slab);
11521160
}
11531161

@@ -1185,7 +1193,7 @@ static void init_object(struct kmem_cache *s, void *object, u8 val)
11851193
s->inuse - poison_size);
11861194
}
11871195

1188-
static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
1196+
static void restore_bytes(struct kmem_cache *s, const char *message, u8 data,
11891197
void *from, void *to)
11901198
{
11911199
slab_fix(s, "Restoring %s 0x%p-0x%p=0x%x", message, from, to - 1, data);
@@ -1200,7 +1208,7 @@ static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
12001208

12011209
static pad_check_attributes int
12021210
check_bytes_and_report(struct kmem_cache *s, struct slab *slab,
1203-
u8 *object, char *what, u8 *start, unsigned int value,
1211+
u8 *object, const char *what, u8 *start, unsigned int value,
12041212
unsigned int bytes, bool slab_obj_print)
12051213
{
12061214
u8 *fault;

0 commit comments

Comments
 (0)