Skip to content

Commit 630fdd5

Browse files
committed
seq_file: seq_show_option_n() is used for precise sizes
When seq_show_option_n() is used, it is for non-string memory that happens to be printable bytes. As such, we must use memcpy() to copy the bytes and then explicitly NUL-terminate the result. Cc: Andy Shevchenko <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Al Viro <[email protected]> Cc: Muchun Song <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 8453e79 commit 630fdd5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

include/linux/seq_file.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,19 @@ static inline void seq_show_option(struct seq_file *m, const char *name,
249249

250250
/**
251251
* seq_show_option_n - display mount options with appropriate escapes
252-
* where @value must be a specific length.
252+
* where @value must be a specific length (i.e.
253+
* not NUL-terminated).
253254
* @m: the seq_file handle
254255
* @name: the mount option name
255256
* @value: the mount option name's value, cannot be NULL
256-
* @length: the length of @value to display
257+
* @length: the exact length of @value to display, must be constant expression
257258
*
258259
* This is a macro since this uses "length" to define the size of the
259260
* stack buffer.
260261
*/
261262
#define seq_show_option_n(m, name, value, length) { \
262263
char val_buf[length + 1]; \
263-
strncpy(val_buf, value, length); \
264+
memcpy(val_buf, value, length); \
264265
val_buf[length] = '\0'; \
265266
seq_show_option(m, name, val_buf); \
266267
}

0 commit comments

Comments
 (0)