Skip to content

Commit 1581a88

Browse files
Tom Zanussirostedt
authored andcommitted
tracing: Remove size restriction on tracing_log_err cmd strings
Currently, tracing_log_err.cmd strings are restricted to a length of MAX_FILTER_STR_VAL (256), which is too short for some commands already seen in the wild (with cmd strings longer than that showing up truncated). Remove the restriction so that no command string is ever truncated. Link: https://lkml.kernel.org/r/ca965f23256b350ebd94b3dc1a319f28e8267f5f.1643319703.git.zanussi@kernel.org Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 3203ce3 commit 1581a88

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

kernel/trace/trace.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7723,34 +7723,60 @@ const struct file_operations trace_min_max_fops = {
77237723
struct err_info {
77247724
const char **errs; /* ptr to loc-specific array of err strings */
77257725
u8 type; /* index into errs -> specific err string */
7726-
u8 pos; /* MAX_FILTER_STR_VAL = 256 */
7726+
u16 pos; /* caret position */
77277727
u64 ts;
77287728
};
77297729

77307730
struct tracing_log_err {
77317731
struct list_head list;
77327732
struct err_info info;
77337733
char loc[TRACING_LOG_LOC_MAX]; /* err location */
7734-
char cmd[MAX_FILTER_STR_VAL]; /* what caused err */
7734+
char *cmd; /* what caused err */
77357735
};
77367736

77377737
static DEFINE_MUTEX(tracing_err_log_lock);
77387738

7739-
static struct tracing_log_err *get_tracing_log_err(struct trace_array *tr)
7739+
static struct tracing_log_err *alloc_tracing_log_err(int len)
7740+
{
7741+
struct tracing_log_err *err;
7742+
7743+
err = kzalloc(sizeof(*err), GFP_KERNEL);
7744+
if (!err)
7745+
return ERR_PTR(-ENOMEM);
7746+
7747+
err->cmd = kzalloc(len, GFP_KERNEL);
7748+
if (!err->cmd) {
7749+
kfree(err);
7750+
return ERR_PTR(-ENOMEM);
7751+
}
7752+
7753+
return err;
7754+
}
7755+
7756+
static void free_tracing_log_err(struct tracing_log_err *err)
7757+
{
7758+
kfree(err->cmd);
7759+
kfree(err);
7760+
}
7761+
7762+
static struct tracing_log_err *get_tracing_log_err(struct trace_array *tr,
7763+
int len)
77407764
{
77417765
struct tracing_log_err *err;
77427766

77437767
if (tr->n_err_log_entries < TRACING_LOG_ERRS_MAX) {
7744-
err = kzalloc(sizeof(*err), GFP_KERNEL);
7745-
if (!err)
7746-
err = ERR_PTR(-ENOMEM);
7747-
else
7768+
err = alloc_tracing_log_err(len);
7769+
if (PTR_ERR(err) != -ENOMEM)
77487770
tr->n_err_log_entries++;
77497771

77507772
return err;
77517773
}
77527774

77537775
err = list_first_entry(&tr->err_log, struct tracing_log_err, list);
7776+
kfree(err->cmd);
7777+
err->cmd = kzalloc(len, GFP_KERNEL);
7778+
if (!err->cmd)
7779+
return ERR_PTR(-ENOMEM);
77547780
list_del(&err->list);
77557781

77567782
return err;
@@ -7811,22 +7837,25 @@ unsigned int err_pos(char *cmd, const char *str)
78117837
*/
78127838
void tracing_log_err(struct trace_array *tr,
78137839
const char *loc, const char *cmd,
7814-
const char **errs, u8 type, u8 pos)
7840+
const char **errs, u8 type, u16 pos)
78157841
{
78167842
struct tracing_log_err *err;
7843+
int len = 0;
78177844

78187845
if (!tr)
78197846
tr = &global_trace;
78207847

7848+
len += sizeof(CMD_PREFIX) + 2 * sizeof("\n") + strlen(cmd) + 1;
7849+
78217850
mutex_lock(&tracing_err_log_lock);
7822-
err = get_tracing_log_err(tr);
7851+
err = get_tracing_log_err(tr, len);
78237852
if (PTR_ERR(err) == -ENOMEM) {
78247853
mutex_unlock(&tracing_err_log_lock);
78257854
return;
78267855
}
78277856

78287857
snprintf(err->loc, TRACING_LOG_LOC_MAX, "%s: error: ", loc);
7829-
snprintf(err->cmd, MAX_FILTER_STR_VAL,"\n" CMD_PREFIX "%s\n", cmd);
7858+
snprintf(err->cmd, len, "\n" CMD_PREFIX "%s\n", cmd);
78307859

78317860
err->info.errs = errs;
78327861
err->info.type = type;
@@ -7844,7 +7873,7 @@ static void clear_tracing_err_log(struct trace_array *tr)
78447873
mutex_lock(&tracing_err_log_lock);
78457874
list_for_each_entry_safe(err, next, &tr->err_log, list) {
78467875
list_del(&err->list);
7847-
kfree(err);
7876+
free_tracing_log_err(err);
78487877
}
78497878

78507879
tr->n_err_log_entries = 0;
@@ -7872,9 +7901,9 @@ static void tracing_err_log_seq_stop(struct seq_file *m, void *v)
78727901
mutex_unlock(&tracing_err_log_lock);
78737902
}
78747903

7875-
static void tracing_err_log_show_pos(struct seq_file *m, u8 pos)
7904+
static void tracing_err_log_show_pos(struct seq_file *m, u16 pos)
78767905
{
7877-
u8 i;
7906+
u16 i;
78787907

78797908
for (i = 0; i < sizeof(CMD_PREFIX) - 1; i++)
78807909
seq_putc(m, ' ');

kernel/trace/trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ extern ssize_t trace_parse_run_command(struct file *file,
18781878
extern unsigned int err_pos(char *cmd, const char *str);
18791879
extern void tracing_log_err(struct trace_array *tr,
18801880
const char *loc, const char *cmd,
1881-
const char **errs, u8 type, u8 pos);
1881+
const char **errs, u8 type, u16 pos);
18821882

18831883
/*
18841884
* Normal trace_printk() and friends allocates special buffers

0 commit comments

Comments
 (0)