From patchwork Thu Jun 1 20:27:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9761087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BA0A8602BC for ; Thu, 1 Jun 2017 20:27:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADD222832D for ; Thu, 1 Jun 2017 20:27:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2BE82852D; Thu, 1 Jun 2017 20:27:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 471BE2832D for ; Thu, 1 Jun 2017 20:27:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751125AbdFAU1j (ORCPT ); Thu, 1 Jun 2017 16:27:39 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36284 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751029AbdFAU1i (ORCPT ); Thu, 1 Jun 2017 16:27:38 -0400 Received: by mail-wm0-f66.google.com with SMTP id k15so14124074wmh.3 for ; Thu, 01 Jun 2017 13:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iibc1AwnJY2bw3wjTHfk/xfyQ2Tq/goQE+bS9OqcZU0=; b=pLlRcxFAHKQwJu17u4wsDh39FlC1IREznAtjRX6NIUcAVeU/nruOYNJAGdhEfdTrPv Dg7HDFVViGP2Q+ms06tbLWDvCLMl2C3Z1XCjf4n1w98qlTbXdJk8cjwphw13PL1qljaG JGeObFb3LXc7MmbkMMcCHJDWwhAsAlINlW+7DfybKHfvq4NVkcFJhEF7RWNeVnjLbXbH R4PELwsns/4tupy3CNSgRFmvcahQEKbUG6hR21cKJkmVXxIcSz5e4QJwMxv8uw/Odcdm E9Qnk94bQTZ0vZCS9Rl/qRXA90T7p7FZxgQYNKuNuzO5Ee/YUVzRFyR8JHN2nUOJ/xbN GpnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iibc1AwnJY2bw3wjTHfk/xfyQ2Tq/goQE+bS9OqcZU0=; b=a7P69ro/iqjzri1+ZYBgs2Zf4z4KMrz+gaO0383gj//u7Nu0K9W3GcDU71Yf/ERQFh hAWr8YEx3Ji97J2yYKZW8ZI9Qtc5Sqr0LCZmoTaSG9yLGpcWgYX4Mbyjt5FfGos8PMH6 KVr22OhL+4yqRPXOMPo+pr3HhMfi5RQlJOV9Yl3UsklaTFBbHXH6k47soYpJvypxvSQe 2/fvSTBQSe/ghXS4SgPRWhpAU98IfH0s2hgxg6TjvNvF3pD/7N0DW1HXLYBi+5YY+Rkj aWqXQdYJgMPQHTcz34LZ81hOeSow39oJRs/voPnbbhAWxrhVuPqBaf/Ij1g4JjkpEFbi w+iQ== X-Gm-Message-State: AODbwcDBUy36+yl6vQBfaDCZF0cnGdwmAHtTffdk5BwyALpAY2m8iGHj 7ouHw5ZFde8m0xgoYtY= X-Received: by 10.28.220.138 with SMTP id t132mr684282wmg.63.1496348856503; Thu, 01 Jun 2017 13:27:36 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:c519:ec79:50ce:6fe3]) by smtp.gmail.com with ESMTPSA id t27sm1427510wra.35.2017.06.01.13.27.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 13:27:36 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Ramsay Jones , Junio C Hamano , Luc Van Oostenryck Subject: [PATCH 2/3] add support for -Wmemcpy-max-count Date: Thu, 1 Jun 2017 22:27:23 +0200 Message-Id: <20170601202724.77597-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170601202724.77597-1-luc.vanoostenryck@gmail.com> References: <84e547c2-8a5b-225c-1363-361e091821f4@ramsayjones.plus.com> <20170601202724.77597-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP sparse will warn if memcpy() (or memset(), copy_from_user(), copy_to_user()) is called with a very large static byte-count. But this warning is given unconditionaly while there are projects where this warning may not be not desired. Change this by making this warning conditional on a new warning flag: -Wmemcpy-max-count=COUNT. Signed-off-by: Luc Van Oostenryck --- lib.c | 2 ++ lib.h | 1 + sparse.1 | 8 ++++++++ sparse.c | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib.c b/lib.c index e1e6a1cbf..90fd2b494 100644 --- a/lib.c +++ b/lib.c @@ -229,6 +229,7 @@ int Wdo_while = 0; int Winit_cstring = 0; int Wenum_mismatch = 1; int Wsparse_error = 0; +int Wmemcpy_max_count = 1; int Wnon_pointer_null = 1; int Wold_initializer = 1; int Wone_bit_signed_bitfield = 1; @@ -506,6 +507,7 @@ static const struct warning { { "enum-mismatch", &Wenum_mismatch }, { "sparse-error", &Wsparse_error }, { "init-cstring", &Winit_cstring }, + { "memcpy-max-count", &Wmemcpy_max_count }, { "non-pointer-null", &Wnon_pointer_null }, { "old-initializer", &Wold_initializer }, { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield }, diff --git a/lib.h b/lib.h index 2c8529f93..8090fe247 100644 --- a/lib.h +++ b/lib.h @@ -116,6 +116,7 @@ extern int Wdo_while; extern int Wenum_mismatch; extern int Wsparse_error; extern int Winit_cstring; +extern int Wmemcpy_max_count; extern int Wnon_pointer_null; extern int Wold_initializer; extern int Wone_bit_signed_bitfield; diff --git a/sparse.1 b/sparse.1 index c924b3a59..efbd78d01 100644 --- a/sparse.1 +++ b/sparse.1 @@ -210,6 +210,14 @@ trouble. Sparse does not issue these warnings by default. . .TP +.B \-Wmemcpy\-max\-count +Warn about call of \fBmemset()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or +\fBcopy_to_user()\fR with a large compile-time byte count. + +Sparse issues these warnings by default. To turn them off, use +\fB\-Wno\-memcpy\-max\-count\fR. +. +.TP .B \-Wnon\-pointer\-null Warn about the use of 0 as a NULL pointer. diff --git a/sparse.c b/sparse.c index 1cb90e20d..aa5979f1a 100644 --- a/sparse.c +++ b/sparse.c @@ -153,7 +153,8 @@ static void check_byte_count(struct instruction *insn, pseudo_t count) return; if (count->type == PSEUDO_VAL) { unsigned long long val = count->value; - if (val > 100000ULL) + if (Wmemcpy_max_count && val > 100000ULL) + warning(insn->pos, "%s with byte count of %llu", show_ident(insn->func->sym->ident), val); return;