From: Dan Carpenter <dan.carpenter@oracle.com>
To: Kees Cook <keescook@chromium.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Peter Rosin <peda@axentia.se>, Wolfram Sang <wsa@kernel.org>,
"Gustavo A. R. Silva" <gustavo@embeddedor.com>,
linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] i2c: mux: harden i2c_mux_alloc() against integer overflows
Date: Fri, 16 Sep 2022 17:55:55 +0300 [thread overview]
Message-ID: <YySOewo2YUY+fk1l@kadam> (raw)
In-Reply-To: <202209160630.CF7AE9708D@keescook>
[-- Attachment #1: Type: text/plain, Size: 746 bytes --]
On Fri, Sep 16, 2022 at 06:31:45AM -0700, Kees Cook wrote:
> On Fri, Sep 16, 2022 at 11:23:25AM +0300, Dan Carpenter wrote:
> > [...]
> > net/ipv6/mcast.c:450 ip6_mc_source() saving 'size_add' to type 'int'
>
> Interesting! Are you able to report the consumer? e.g. I think a bunch
> of these would be fixed by:
>
Are you asking if I can add "passed to sock_kmalloc()" to the report?
It's possible but it's kind of a headache the way this code is written.
When you pass a function to another function in Smatch:
frob(size_add());
Then Smatch creates a fake assignment: "frob(fake_assign = size_add());"
and parses that instead. So this check only looks at the
"fake_assign = size_add();" assignment.
Attached.
regards,
dan carpenter
[-- Attachment #2: check_overflow_truncated.c --]
[-- Type: text/x-csrc, Size: 1545 bytes --]
/*
* Copyright (C) 2022 Oracle.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
*/
#include "smatch.h"
#include "smatch_extra.h"
#include "smatch_slist.h"
static int my_id;
static void check_size_t(const char *fn, struct expression *expr, void *unused)
{
struct symbol *type;
type = get_type(expr->left);
if (types_equiv(type, &long_ctype) ||
types_equiv(type, &ulong_ctype))
return;
sm_msg("saving '%s' to type '%s'", fn, type_to_str(type));
}
void check_overflow_truncated(int id)
{
my_id = id;
if (option_project != PROJ_KERNEL)
return;
add_function_assign_hook("size_mul", &check_size_t, NULL);
add_function_assign_hook("size_add", &check_size_t, NULL);
add_function_assign_hook("size_sub", &check_size_t, NULL);
add_function_assign_hook("__ab_c_size", &check_size_t, NULL);
add_function_assign_hook("array_size", &check_size_t, NULL);
add_function_assign_hook("array3_size", &check_size_t, NULL);
}
next prev parent reply other threads:[~2022-09-16 14:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-15 11:30 [PATCH] i2c: mux: harden i2c_mux_alloc() against integer overflows Dan Carpenter
2022-09-15 13:36 ` Peter Rosin
2022-09-15 13:51 ` Gustavo A. R. Silva
2022-09-15 14:09 ` Dan Carpenter
2022-09-16 8:07 ` Kees Cook
2022-09-16 8:23 ` Dan Carpenter
2022-09-16 13:31 ` Kees Cook
2022-09-16 14:55 ` Dan Carpenter [this message]
2022-09-16 21:31 ` Kees Cook
2022-09-16 8:01 ` Kees Cook
2022-09-16 8:20 ` Dan Carpenter
2022-09-16 19:31 ` Wolfram Sang
2022-09-19 6:35 ` Dan Carpenter
2022-09-21 20:13 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YySOewo2YUY+fk1l@kadam \
--to=dan.carpenter@oracle.com \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=keescook@chromium.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peda@axentia.se \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox