From patchwork Thu Jun 1 20:27:24 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: 9761089 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 A1F9C602BC for ; Thu, 1 Jun 2017 20:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96D522832D for ; Thu, 1 Jun 2017 20:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B9812852D; Thu, 1 Jun 2017 20:27:41 +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 22CFA2832D for ; Thu, 1 Jun 2017 20:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751029AbdFAU1k (ORCPT ); Thu, 1 Jun 2017 16:27:40 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33779 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751114AbdFAU1j (ORCPT ); Thu, 1 Jun 2017 16:27:39 -0400 Received: by mail-wm0-f68.google.com with SMTP id b84so14127773wmh.0 for ; Thu, 01 Jun 2017 13:27:38 -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=fTWRaoOj6S41RxLGD6D4CL3n23V5LTcZ2lI4gWfdD2o=; b=ExkmOxih04iQy0t5h/Pyom52ypFNThwghVqZETXNC3YO/cyIYkhtw4+fItB6EOBQYm dsiqfNbhfB1SD8tAsm4siM00siCUhNnDd5GtbwOtGBE7us9gwEyZgwFbexg305YGCgqY mh0ARoNHtC90CmWOc8YO88eFscTL8cO7ZbngZTVpal82UF05K/af17gw9mPvhnB73t6K aX2+Yt9UE0CMf3eza0sh2az9as3NzCGIkRco1UBGovGMd9lJeuB3rxV6QDPUZ9NugAgO VtE7DcrkBiY7h2Jc2cNHlDVp3k+c/12NvxiZAcrCuoQzI93x4L046WvdTfX5eplu+YbQ +DRQ== 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=fTWRaoOj6S41RxLGD6D4CL3n23V5LTcZ2lI4gWfdD2o=; b=C/gbHojpXPlzcNqko4aUqbAz03YxLxspK6t0khAp5C4V89mBN9Zm+ztcSrUCLvvpov 72Whxhk6ScFfL2XAPEJadDuiVTzy2/XYa+9rml08JG+Ewe9DJd12AIHFX0qZqWEMrG63 eAgNu8bgnSC6HhkB9zrJwgT9MFpotDcrmn3IKJxgF3tMWCdUa1k46X7P6yKWEJOq+70q USpWpqmDrBkGbMKj8CJHqKyMRIFDQ9GlCKyZ+nmyMuESwR/BN0OOUqtC59rFYASKGsNJ 9lNZoOs1JpB73BxaWH6GxPvpbi7Ig5mttiGvmflGxWhmI7sBoIi7N1g2fsD7RkPp6p1m Jfww== X-Gm-Message-State: AODbwcBjYm/AU8wF5kTlwydWKklb1EY87WkImij4zmfwX8rSe+7K6N3K v2OYxvGoTb10ORuWkqY= X-Received: by 10.223.183.20 with SMTP id l20mr2577580wre.178.1496348857642; Thu, 01 Jun 2017 13:27:37 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 13:27:37 -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 3/3] add support for -fmemcpy-max-count Date: Thu, 1 Jun 2017 22:27:24 +0200 Message-Id: <20170601202724.77597-4-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 By default, sparse will warn if memcpy() (or memset(), copy_from_user(), copy_to_user()) is called with a very large static byte-count. But the limit is currently fixed at 100000, which may be fine for some uses but not for others. For example, this value is too low for sparse to be used on the git tree where, for example, some array used to sort the index is cleared with memset(). Change this by making the limit configurable via a new flag: -fmemcpy-max-count. Signed-off-by: Luc Van Oostenryck --- lib.c | 16 ++++++++++++++++ lib.h | 1 + sparse.1 | 10 ++++++++++ sparse.c | 3 +-- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib.c b/lib.c index 90fd2b494..1378cc243 100644 --- a/lib.c +++ b/lib.c @@ -256,6 +256,7 @@ int dbg_dead = 0; int fmem_report = 0; int fdump_linearize; +unsigned long fmemcpy_max_count = 100000; int preprocess_only; @@ -670,6 +671,19 @@ static char **handle_switch_O(char *arg, char **next) return next; } +static char **handle_switch_fmemcpy_max_count(char *arg, char **next) +{ + unsigned long val; + char *end; + + val = strtoul(arg, &end, 0); + if (*end != '\0' || end == arg) + die("error: missing argument to \"-fmemcpy-max-count=\""); + + fmemcpy_max_count = val; + return next; +} + static char **handle_switch_ftabstop(char *arg, char **next) { char *end; @@ -713,6 +727,8 @@ static char **handle_switch_f(char *arg, char **next) return handle_switch_ftabstop(arg+8, next); if (!strncmp(arg, "dump-", 5)) return handle_switch_fdump(arg+5, next); + if (!strncmp(arg, "memcpy-max-count=", 17)) + return handle_switch_fmemcpy_max_count(arg+17, next); /* handle switches w/ arguments above, boolean and only boolean below */ if (handle_simple_switch(arg, "mem-report", &fmem_report)) diff --git a/lib.h b/lib.h index 8090fe247..b7cb451e0 100644 --- a/lib.h +++ b/lib.h @@ -143,6 +143,7 @@ extern int dbg_dead; extern int fmem_report; extern int fdump_linearize; +extern unsigned long fmemcpy_max_count; extern int arch_m64; diff --git a/sparse.1 b/sparse.1 index efbd78d01..932ac82ef 100644 --- a/sparse.1 +++ b/sparse.1 @@ -216,6 +216,9 @@ Warn about call of \fBmemset()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or Sparse issues these warnings by default. To turn them off, use \fB\-Wno\-memcpy\-max\-count\fR. + +The limit can be changed with \fB\-fmemcpy\-max\-count=COUNT\fR, +the default being \fB100000\fR. . .TP .B \-Wnon\-pointer\-null @@ -364,6 +367,13 @@ Report some statistics about memory allocation used by the tool. . .SH OTHER OPTIONS .TP +.B \-fmemcpy-limit=COUNT +By default, sparse will warn if \fBmemcpy()\fR (or \fBmemset()\fR, +\fBcopy_from_user()\fR, copy_to_user()\fR) is called with a very large +(known at compile-time) byte-count. COUNT is the value under which +no such warning will be given. The default limit is 100000. +. +.TP .B \-ftabstop=WIDTH Set the distance between tab stops. This helps sparse report correct column numbers in warnings or errors. If the value is less than 1 or diff --git a/sparse.c b/sparse.c index aa5979f1a..bceacd94e 100644 --- a/sparse.c +++ b/sparse.c @@ -153,8 +153,7 @@ static void check_byte_count(struct instruction *insn, pseudo_t count) return; if (count->type == PSEUDO_VAL) { unsigned long long val = count->value; - if (Wmemcpy_max_count && val > 100000ULL) - + if (Wmemcpy_max_count && val > fmemcpy_max_count) warning(insn->pos, "%s with byte count of %llu", show_ident(insn->func->sym->ident), val); return;