Re: [RFC PATCH 0/1] Integer overflows while scanning for integers
From: Kees Cook
Date: Wed Jun 07 2023 - 19:36:20 EST
On Thu, Jun 08, 2023 at 12:37:54AM +0200, Richard Weinberger wrote:
> Hi!
>
> Lately I wondered whether users of integer scanning functions check
> for overflows.
> To detect such overflows around scanf I came up with the following
> patch. It simply triggers a WARN_ON_ONCE() upon an overflow.
>
> After digging into various scanf users I found that the network device
> naming code can trigger an overflow.
>
> e.g:
> $ ip link add 1 type veth peer name 9999999999
> $ ip link set name "%d" dev 1
>
> It will trigger the following WARN_ON_ONCE():
> ------------[ cut here ]------------
> WARNING: CPU: 2 PID: 433 at lib/vsprintf.c:3701 vsscanf+0x6ce/0x990
Hm, it's considered a bug if a WARN or BUG can be reached from
userspace, so this probably needs to be rearranged (or callers fixed).
Do we need to change the scanf API for sane use inside the kernel?
-Kees
--
Kees Cook