Re: [PATCH 1/8] lkdtm: change snprintf to scnprintf for possible overflow
From: Kees Cook
Date: Mon Jan 14 2019 - 20:07:35 EST
On Mon, Jan 14, 2019 at 5:02 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> On Sat, Jan 12, 2019 at 7:28 AM Willy Tarreau <w@xxxxxx> wrote:
> > From: Silvio Cesare <silvio.cesare@xxxxxxxxx>
> > Change snprintf to scnprintf. There are generally two cases where using
> > snprintf causes problems.
>
> (I didn't find a 0/8 cover letter, so I'm replying here...)
I forgot to mention: can we please get a Coccinelle rule added to
catch these cases in the future? (And make sure sfr is running it? :)
)
My attempt at it was:
@@
expression LEN, BUF, SIZE;
identifier FUNC;
@@
LEN += snprintf(BUF + LEN, SIZE - LEN, ...);
... when != LEN > SIZE
when != LEN >= SIZE
* FUNC(..., LEN, ...)
But this needs adjustment to deal with some false positives (like using min()).
--
Kees Cook