Skip to content

Commit fddca7d

Browse files
committed
tracing/boot: Test strscpy() against less than zero for error
Instead of checking for -E2BIG, it is better to just check for less than zero of strscpy() for error. Testing for -E2BIG is not very robust, and the calling code does not really care about the error code, just that there was an error. One of the updates to convert strlcpy() to strscpy() had a v2 version that changed the test from testing against -E2BIG to less than zero, but I took the v1 version that still tested for -E2BIG. Link: https://lore.kernel.org/linux-trace-kernel/[email protected]/ Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Mark Rutland <[email protected]> Cc: Azeem Shaikh <[email protected]> Cc: Kees Cook <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 931a2ca commit fddca7d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/trace/trace_boot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node)
3131

3232
/* Common ftrace options */
3333
xbc_node_for_each_array_value(node, "options", anode, p) {
34-
if (strscpy(buf, p, ARRAY_SIZE(buf)) == -E2BIG) {
34+
if (strscpy(buf, p, ARRAY_SIZE(buf)) < 0) {
3535
pr_err("String is too long: %s\n", p);
3636
continue;
3737
}
@@ -87,7 +87,7 @@ trace_boot_enable_events(struct trace_array *tr, struct xbc_node *node)
8787
const char *p;
8888

8989
xbc_node_for_each_array_value(node, "events", anode, p) {
90-
if (strscpy(buf, p, ARRAY_SIZE(buf)) == -E2BIG) {
90+
if (strscpy(buf, p, ARRAY_SIZE(buf)) < 0) {
9191
pr_err("String is too long: %s\n", p);
9292
continue;
9393
}
@@ -486,15 +486,15 @@ trace_boot_init_one_event(struct trace_array *tr, struct xbc_node *gnode,
486486

487487
p = xbc_node_find_value(enode, "filter", NULL);
488488
if (p && *p != '\0') {
489-
if (strscpy(buf, p, ARRAY_SIZE(buf)) == -E2BIG)
489+
if (strscpy(buf, p, ARRAY_SIZE(buf)) < 0)
490490
pr_err("filter string is too long: %s\n", p);
491491
else if (apply_event_filter(file, buf) < 0)
492492
pr_err("Failed to apply filter: %s\n", buf);
493493
}
494494

495495
if (IS_ENABLED(CONFIG_HIST_TRIGGERS)) {
496496
xbc_node_for_each_array_value(enode, "actions", anode, p) {
497-
if (strscpy(buf, p, ARRAY_SIZE(buf)) == -E2BIG)
497+
if (strscpy(buf, p, ARRAY_SIZE(buf)) < 0)
498498
pr_err("action string is too long: %s\n", p);
499499
else if (trigger_process_regex(file, buf) < 0)
500500
pr_err("Failed to apply an action: %s\n", p);

0 commit comments

Comments
 (0)