mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	bpf: fix check of allowed specifiers in bpf_trace_printk
A format string consisting of "%p" or "%s" followed by an invalid
specifier (e.g. "%p%\n" or "%s%") could pass the check which
would make format_decode (lib/vsprintf.c) to warn.
Fixes: 9c959c863f ("tracing: Allow BPF programs to call bpf_trace_printk()")
Reported-by: syzbot+1ec5c5ec949c4adaa0c4@syzkaller.appspotmail.com
Signed-off-by: Martynas Pumputis <m@lambda.lt>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
			
			
This commit is contained in:
		
							parent
							
								
									813961de3e
								
							
						
					
					
						commit
						1efb6ee3ed
					
				
					 1 changed files with 5 additions and 3 deletions
				
			
		| 
						 | 
					@ -196,11 +196,13 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
 | 
				
			||||||
			i++;
 | 
								i++;
 | 
				
			||||||
		} else if (fmt[i] == 'p' || fmt[i] == 's') {
 | 
							} else if (fmt[i] == 'p' || fmt[i] == 's') {
 | 
				
			||||||
			mod[fmt_cnt]++;
 | 
								mod[fmt_cnt]++;
 | 
				
			||||||
			i++;
 | 
								/* disallow any further format extensions */
 | 
				
			||||||
			if (!isspace(fmt[i]) && !ispunct(fmt[i]) && fmt[i] != 0)
 | 
								if (fmt[i + 1] != 0 &&
 | 
				
			||||||
 | 
								    !isspace(fmt[i + 1]) &&
 | 
				
			||||||
 | 
								    !ispunct(fmt[i + 1]))
 | 
				
			||||||
				return -EINVAL;
 | 
									return -EINVAL;
 | 
				
			||||||
			fmt_cnt++;
 | 
								fmt_cnt++;
 | 
				
			||||||
			if (fmt[i - 1] == 's') {
 | 
								if (fmt[i] == 's') {
 | 
				
			||||||
				if (str_seen)
 | 
									if (str_seen)
 | 
				
			||||||
					/* allow only one '%s' per fmt string */
 | 
										/* allow only one '%s' per fmt string */
 | 
				
			||||||
					return -EINVAL;
 | 
										return -EINVAL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue