Skip to content

Commit 8118f19

Browse files
alejandro-colomarakpm00
authored andcommitted
mm: fix benign off-by-one bugs
We were wasting a byte due to an off-by-one bug. s[c]nprintf() doesn't write more than $2 bytes including the null byte, so trying to pass 'size-1' there is wasting one byte. Link: https://lkml.kernel.org/r/9c38dd009c17b0219889c7089d9bdde5aaf28a8e.1765449750.git.alx@kernel.org Signed-off-by: Alejandro Colomar <[email protected]> Acked-by: Marco Elver <[email protected]> Cc: Kees Cook <[email protected]> Cc: Christopher Bazley <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Jann Horn <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Al Viro <[email protected]> Cc: Maciej W. Rozycki <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 436debc commit 8118f19

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

mm/kfence/kfence_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static bool report_matches(const struct expect_report *r)
110110

111111
/* Title */
112112
cur = expect[0];
113-
end = &expect[0][sizeof(expect[0]) - 1];
113+
end = ARRAY_END(expect[0]);
114114
switch (r->type) {
115115
case KFENCE_ERROR_OOB:
116116
cur += scnprintf(cur, end - cur, "BUG: KFENCE: out-of-bounds %s",
@@ -140,7 +140,7 @@ static bool report_matches(const struct expect_report *r)
140140

141141
/* Access information */
142142
cur = expect[1];
143-
end = &expect[1][sizeof(expect[1]) - 1];
143+
end = ARRAY_END(expect[1]);
144144

145145
switch (r->type) {
146146
case KFENCE_ERROR_OOB:

mm/kmsan/kmsan_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static bool report_matches(const struct expect_report *r)
105105

106106
/* Title */
107107
cur = expected_header;
108-
end = &expected_header[sizeof(expected_header) - 1];
108+
end = ARRAY_END(expected_header);
109109

110110
cur += scnprintf(cur, end - cur, "BUG: KMSAN: %s", r->error_type);
111111

0 commit comments

Comments
 (0)