From patchwork Sat Jun 3 07:47:26 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: 9764017 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 65BBD60360 for ; Sat, 3 Jun 2017 07:47:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 581E22858A for ; Sat, 3 Jun 2017 07:47:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D3842859A; Sat, 3 Jun 2017 07:47:38 +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 EAD452858A for ; Sat, 3 Jun 2017 07:47:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751203AbdFCHrh (ORCPT ); Sat, 3 Jun 2017 03:47:37 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36602 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751077AbdFCHrg (ORCPT ); Sat, 3 Jun 2017 03:47:36 -0400 Received: by mail-wm0-f65.google.com with SMTP id k15so22089472wmh.3 for ; Sat, 03 Jun 2017 00:47:35 -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=Sa0Wqq8cMPdNx3LJpKRzRUrKNNJX+e/guYYqWIHnG0o=; b=bEYOoBV9afMC9lrWx/wSyG9adcghZRYpzjngl3WlkCn6chokTnNMvfR3dR2JadkZJ/ we+BBPIjf7KViEtCJ6r/9X9vrwNpKkojBUPYhZtscEGxMGRu7xY2Mg1N6nNPoeqllJmT ObC7upH5GzkRKBy7LYsInV9GboNGJTXgCOaZFFI8royJBTAXEUNemW3O9QrdkIxG9djK v/8Da0eJzhJ+MDUc70snrs0CHgUqySn+09pGXDxIAoiuycg6czF+epwkVjEvhZDr69m0 DD/a42iOp6sgZhuM5PDYHWikcYjlCUdOHXzSoZ7fUvhEjcUOd4ZvygACn/gYuPJNmAq8 2yZQ== 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=Sa0Wqq8cMPdNx3LJpKRzRUrKNNJX+e/guYYqWIHnG0o=; b=c0Ukk55nKS28wTLO2gLdQstrEjNcx/7aBazwHN/OeO2wZykaVeGqVyDuKW8823gtVz 6lcVo7o154uH9oBXRJgGbZZ8O4iqoWhXnWbEFXs1Dd2KAsTPTQpiXwfFxAsSReLdHIlQ rKqhmxvm9ZlmMtpXOSy7up/Bs/n9xCDsdyvwRkSBESnob8qRBZgMKShL6Gso4rhfnTpa LGszVIk0PJU4FRaou/vO3VoMayFgDv9BA3jMtk38f0vHTkBjYpuoMAgFW6Rh1N64lLbE Wvj/Twn9wFqYye+BpuFs2FMrfyUPSnuH23bLefJ1HfsSlKi3zY8CJcxLSoFKDqNAFP7H p5Dw== X-Gm-Message-State: AODbwcAlDZ3zHcJSfhJS16YBxqQkcXYI4nhD9x5Lp9OWpFAR+jIGMsul lm3CIRPMBU9Wm7gSQE0= X-Received: by 10.80.185.3 with SMTP id m3mr8870816ede.41.1496476055059; Sat, 03 Jun 2017 00:47:35 -0700 (PDT) Received: from localhost.localdomain ([2a02:a03f:89c:5400:65b4:e9ec:d7a6:723a]) by smtp.gmail.com with ESMTPSA id f48sm126331eda.42.2017.06.03.00.47.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Jun 2017 00:47:34 -0700 (PDT) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Chris Li , Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v2 2/3] add support for -Wmemcpy-max-count Date: Sat, 3 Jun 2017 09:47:26 +0200 Message-Id: <20170603074727.66945-3-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170603074727.66945-1-luc.vanoostenryck@gmail.com> References: <20170603074727.66945-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: -W[no-]memcpy-max-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..df3c7f442 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 \fBmemcpy()\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;