lkml.org 
[lkml]   [2019]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 1/8] lkdtm: change snprintf to scnprintf for possible overflow
On Mon, Jan 14, 2019 at 5:02 PM Kees Cook <keescook@chromium.org> wrote:
> On Sat, Jan 12, 2019 at 7:28 AM Willy Tarreau <w@1wt.eu> wrote:
> > From: Silvio Cesare <silvio.cesare@gmail.com>
> > 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 &gt; SIZE
when != LEN &gt;= SIZE
* FUNC(..., LEN, ...)

But this needs adjustment to deal with some false positives (like using min()).

--
Kees Cook

\
 
 \ /
  Last update: 2019-01-15 02:08    [W:0.203 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site