Message ID | 20180509004229.36341-8-keescook@chromium.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 70DAD6054D for <patchwork-linux-mm@patchwork.kernel.org>; Wed, 9 May 2018 00:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4775828FF5 for <patchwork-linux-mm@patchwork.kernel.org>; Wed, 9 May 2018 00:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1172A28F9D; Wed, 9 May 2018 00:44:29 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C3B92963E for <patchwork-linux-mm@patchwork.kernel.org>; Wed, 9 May 2018 00:43:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 301106B02F5; Tue, 8 May 2018 20:42:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 289BE6B02F6; Tue, 8 May 2018 20:42:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 104F06B02F7; Tue, 8 May 2018 20:42:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id BBF3C6B02F5 for <linux-mm@kvack.org>; Tue, 8 May 2018 20:42:46 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id 72-v6so2749791pld.19 for <linux-mm@kvack.org>; Tue, 08 May 2018 17:42:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=PPeI6Fc1WIiUv3CI2eKARVZpHUloUTnaY/Tk9c6TzH0=; b=LgLOW5366Q7+alEiYgD1r9IrMe9o2n7NDCc2YxnvUQWDorGf8iGQItmNOjg3Yr7Fbt fFxoxaD9Nxfj9XQ1WsAzn46h1i18XZndX6WgbpEZK1LdcKeCxS3gh15tjfCedadLvrdO bwZ/t6l2/T/mhijfIz2XEiJIemaaKvyioCgcvZmO2fRrKE1ev9J/FSQXL5iAfnU41tLA uRIZIqd7X/UO59E1SL0O5NeiHNsWxXFytSvgp0uBTE5LidIpfvdB2q2Jk8Pc+7/ZYO4C YzROuk7/25zasYkwlRirvdAyK9U6CksUs6kgijwoElXKCkJ8QZbUrWwqSTUPuXEyiP7S qz0A== X-Gm-Message-State: ALQs6tD3kURBl2ZqTVdIesKQ5rzf032wRiq1TM7c2pDPDIM2WL+bz6+9 A4KtX7coVoFwbHomqWkiicpYmAHDGjTVkEAR+e963zVLBAi1xWCT8OPqPKBJBNN0UM381qro0eR Pry4NOQ5V+rG2SPmG7Kf4PDP4mH7hW6pMCW2zB2FJZbesszpewn/bYS/xu1pn4HQJxBMR/TYofY o+6rxld3jZelsf8lahLV3oKJ8VutMvuH0cLOYVqTqSe+2yc0GwRYwZ0+Bl0qquNr0TfRmZK9jKm tYOoY/8fLsvpfhUyZdwidTjIXCaB8nMwolpJ5FqhNPU7IuWPBDMnpGCwR0lE4lllyIP9dcdQxnU Dlh75YWuLosYteIe75MRKWBy5/hGi3Z5bH1CR/+nP339TMw2WQvnU4SVCsJAPezACWCEJT+/6Di a X-Received: by 2002:a17:902:3f83:: with SMTP id a3-v6mr43607331pld.279.1525826566476; Tue, 08 May 2018 17:42:46 -0700 (PDT) X-Received: by 2002:a17:902:3f83:: with SMTP id a3-v6mr43607301pld.279.1525826565729; Tue, 08 May 2018 17:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525826565; cv=none; d=google.com; s=arc-20160816; b=p68bomzPmG44XD1XqcLYcmmRKAC0p9FE2foHUx/dRNoW0lMvPOkkd5Oudrhd3gV3CD 1dU6kk2krJ1BLYwTSpmHaUK9yYF5mA8zR701rv3lDo96bXD7uHLJOrdZUDmeBMMzWH/m 5uKOkzj9GYhVB539SJkPwvhJcpsUzxCjgwuWJpTUw8AtnUsh8nVGmL5T1494FM0e9+vT jtH2soAP8zn3qAwtO0Ho4ps8ncrjLOaJGtaYndZlvUGKelUNJ3cAymdBySGBCMhjRE7W ANgIfJqad6h58zpxyi91pw6A05aFUz0hTWU6XtgdsBGV736G8xuJVC7v+g+usDUPU7jM cXvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=PPeI6Fc1WIiUv3CI2eKARVZpHUloUTnaY/Tk9c6TzH0=; b=gfaahFvTB7B91hs5OG6opLKX+5pTWolV7Egit5NlwoyinP3QsLYsxmSs4q0drXMo69 00oz4g4JMX8ZnNqb5A5U+55yA8FyiSDy6DWfbwIlfdi+ZyJaBl0ZMdO9MrzqKhhzht5h RIOoHTRwuuem0028awrn94uR+VJ1tyy7onjzR6+uFowXQIySVsllrpwBSbcLAHFYdOqi ditG0kHsr7lnEYf8PPSdF8RHRytEhvHTcDOayZd+iuJvKsc1hN6FwWdav2XuDPafhLyR IEu3myv4Lenoy48JG3guWbLrkPtvKnXMkNGWAXqINoOec7SotS24d8y4xq5MWCFgi9cO BTqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ti3M4KhF; spf=pass (google.com: domain of keescook@chromium.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c4-v6sor8268419plo.93.2018.05.08.17.42.45 for <linux-mm@kvack.org> (Google Transport Security); Tue, 08 May 2018 17:42:45 -0700 (PDT) Received-SPF: pass (google.com: domain of keescook@chromium.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Ti3M4KhF; spf=pass (google.com: domain of keescook@chromium.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PPeI6Fc1WIiUv3CI2eKARVZpHUloUTnaY/Tk9c6TzH0=; b=Ti3M4KhF8uBei+5fApihTwmQe/yaG8eyb6/Tt0dLmJsP0iqKp6AionjXWz46yB0cfJ XDx+0VVKV3kPkjM089dvRQ07dECcMqUGPU8dVHrYG75VDd8X2Aw5F19W60mEu51dXq8K 5PjbSkp9b4UdkoBMyGxkwFCfrqwMV1BsgcqLs= X-Google-Smtp-Source: AB8JxZoCGNoAm3MjQMCf7bkdg8CG2jZziC0BxdS1BbDCtlXHrA+HFi52gwv8E2P1aDc0chEnTVlbPg== X-Received: by 2002:a17:902:d808:: with SMTP id a8-v6mr43744255plz.177.1525826565494; Tue, 08 May 2018 17:42:45 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id p126-v6sm41302157pga.28.2018.05.08.17.42.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 May 2018 17:42:43 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Matthew Wilcox <mawilcox@microsoft.com> Cc: Kees Cook <keescook@chromium.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Subject: [PATCH 07/13] treewide: Use struct_size() for vmalloc()-family Date: Tue, 8 May 2018 17:42:23 -0700 Message-Id: <20180509004229.36341-8-keescook@chromium.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509004229.36341-1-keescook@chromium.org> References: <20180509004229.36341-1-keescook@chromium.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: <linux-mm.kvack.org> X-Virus-Scanned: ClamAV using ClamSMTP |
diff --git a/drivers/gpu/drm/nouveau/nvkm/core/ramht.c b/drivers/gpu/drm/nouveau/nvkm/core/ramht.c index ccba4ae73cc5..8162e3d2359c 100644 --- a/drivers/gpu/drm/nouveau/nvkm/core/ramht.c +++ b/drivers/gpu/drm/nouveau/nvkm/core/ramht.c @@ -144,8 +144,7 @@ nvkm_ramht_new(struct nvkm_device *device, u32 size, u32 align, struct nvkm_ramht *ramht; int ret, i; - if (!(ramht = *pramht = vzalloc(sizeof(*ramht) + - (size >> 3) * sizeof(*ramht->data)))) + if (!(ramht = *pramht = vzalloc(struct_size(ramht, data, (size >> 3))))) return -ENOMEM; ramht->device = device;
This only finds one hit in the entire tree, but here's the Coccinelle: // Directly refer to structure's field @@ identifier alloc =~ "vmalloc|vzalloc"; identifier VAR, ELEMENT; expression COUNT; @@ - alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT)) + alloc(struct_size(VAR, ELEMENT, COUNT)) // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL); @@ identifier alloc =~ "vmalloc|vzalloc"; identifier VAR, ELEMENT; expression COUNT; @@ - alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0])) + alloc(struct_size(VAR, ELEMENT, COUNT)) // Same pattern, but can't trivially locate the trailing element name, // or variable name. @@ identifier alloc =~ "vmalloc|vzalloc"; expression SOMETHING, COUNT, ELEMENT; @@ - alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT)) + alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT)) Signed-off-by: Kees Cook <keescook@chromium.org> --- drivers/gpu/drm/nouveau/nvkm/core/ramht.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)