Message ID | 20180601004233.37822-11-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 4E2D9602BC for <patchwork-linux-mm@patchwork.kernel.org>; Fri, 1 Jun 2018 00:44:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48E2328E43 for <patchwork-linux-mm@patchwork.kernel.org>; Fri, 1 Jun 2018 00:44:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DA6A28E58; Fri, 1 Jun 2018 00:44:08 +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 C7AAD28E43 for <patchwork-linux-mm@patchwork.kernel.org>; Fri, 1 Jun 2018 00:44:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43BEB6B026D; Thu, 31 May 2018 20:43:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3ECC26B026E; Thu, 31 May 2018 20:43:52 -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 1EE7D6B026F; Thu, 31 May 2018 20:43:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id D47606B026D for <linux-mm@kvack.org>; Thu, 31 May 2018 20:43:51 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id z5-v6so13522697pfz.6 for <linux-mm@kvack.org>; Thu, 31 May 2018 17:43:51 -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=uanbYC6JTcEuw5Hg1YECg6yuL6Sg3qnG8PzuzPYRwRZ8oNCUYAfNJklILLTDVCWgaJ fwg0i0h7tN7Br3/abhFpdgoPfnMReVlXepwluyVtfommB2XBYZzckIMRKAySzmc/g/gi z/f72b9yIy0qcARzL9GLzqPnkfgu3iTAhf4CxC7x7AF+SlQo3BKp8RTt8B/tN80Bwwxy wWDygTiXsNX+qbrPJ/H50VuUzMOlreX2ScYnOlasKeBPoLscLtf7NoUJQjTbS5zLBfjY oalVh8BzdWxsnD+ftBdQndrwQmboXJ8tGL78iv9noWvsne75eJxGhVdFa+s7sbVSLglI pSgQ== X-Gm-Message-State: ALKqPwcgBeXx+m91DLAvpmjVjt0TG/PsJf/j97Q5GLCR6y4TVKn1uxy4 wG7lVLFnrZQTIstvcQWlTl1P+7G0fxU3mr4nU2JIXQFOyBNEZ87PtdtEX9w41P89m03gvgewpUE i0rlTmSG8XEVmbaU4WaMBbGGEeXmNf2ACH7eLAJCQeZOOSgGvh4iIOAX4eOZJnLOMpNtOnXJUfJ PN/qSZGP/e/pfSmML/BDc/oc0sVlqjstLyOlHrQ1F+CFT4guPHSTf1+7jjnY4xtLEx22fXu5Jq4 wYjT6Tgx8A2kcofIEIT6achxFYVyuZwmZn11pYClPBrQ7QWaY7dTlwQzlsYVS1+/AK3mfQwqlWJ pP3ikKQbiiSEak34iZWLPi5mJN9p2f3RVfzoxaSGGPg7uFyi2JJ/UgcPOS06+WTx2yBT8krWaO7 2 X-Received: by 2002:a62:404f:: with SMTP id n76-v6mr8775993pfa.185.1527813831553; Thu, 31 May 2018 17:43:51 -0700 (PDT) X-Received: by 2002:a62:404f:: with SMTP id n76-v6mr8775944pfa.185.1527813830574; Thu, 31 May 2018 17:43:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527813830; cv=none; d=google.com; s=arc-20160816; b=JaliSRHrynNELcBeguUD15lSW4sknyN+gZmBjYDbxoYrzzpwPdIC/mxKTn2GQ0gZ2z gxCQNB4sGZ2dZrU60KlnKQ5ay0LktkGa4mqivieHbncyX3fM1VU9fnkahpRXrKdzXF2I dHIbHEkUahBr61INLmx1Zvt+kguN4eDGwF8W5DOZEdJiFd66Wxhx8tZbZsTW29mhxmyE udU0uySeuP7S+Cpj4ml+P71F1HuMg7fMzaFlLUMcStdN1EmEyJq/M9XIp05ysePKnYnI HOyMArhWiz6h2XFZtL546Gc5EaDLR5Aeg+ZAGYPlPwVrjq4O198egnftEcaKMom5+Dhd zfQA== 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=AjORNmF3TQiqrdl15Fb6hheW0n2loeSM06FVXTzBdZjn+LJukFNav4gcQrq5CFJlOm yvyWZ75eHHqQCCqyQeTaJi8CE3ls6SVJdqTMkttaM/CRa0j//RJjCFHHydhSx8MIg9wJ UYPEFase3gi1MJ3sMKrGY1RuNtjYfb0kpUHLp4mp0z+2yEtomv2/FAuSpNUl57dq0Vnq GUuwOUimjfQ9Ito+UphMZMCY5bMZfr3BzHf9NmEDfJU8ell+zB+7wd5juTssPLxE6QWJ IqmYcYAI4K9oGNFCos9zSQ1kTwlLo1SWJtlVO1FUqiKaSojP50Fd8/YcUEhd7cZYX4VA ietQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YPLBQvsI; 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 p62-v6sor4179183pfj.101.2018.05.31.17.43.50 for <linux-mm@kvack.org> (Google Transport Security); Thu, 31 May 2018 17:43:50 -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=YPLBQvsI; 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=YPLBQvsIedsEzQUz3dNwDzhBI3aYQkAyJbwJV6Dl/5v8Ifr8L+hZRvWnJK6cDIZHNZ KJV2UfpluAqs1syomAVjtjzN6iK7KJJz9cItRtqaWrNST6LVO5yATzBqNTyo67qUABct nLS6Afr9gXshsQTVDqgcT9+GTusKiza3KlNAE= X-Google-Smtp-Source: ADUXVKJX9TW3gi+cqvdEbUht32fQfADsCnB16Yvm8Tm3U7acQY03/IFZcA3i1+tdguO6nvvhxXRwTw== X-Received: by 2002:aa7:8084:: with SMTP id v4-v6mr8744516pff.105.1527813830338; Thu, 31 May 2018 17:43:50 -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 t17-v6sm6067290pfj.75.2018.05.31.17.43.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 17:43:46 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Matthew Wilcox <mawilcox@microsoft.com> Cc: Kees Cook <keescook@chromium.org>, Linus Torvalds <torvalds@linux-foundation.org>, Rasmus Villemoes <linux@rasmusvillemoes.dk>, Matthew Wilcox <willy@infradead.org>, LKML <linux-kernel@vger.kernel.org>, Linux-MM <linux-mm@kvack.org>, Kernel Hardening <kernel-hardening@lists.openwall.com> Subject: [PATCH v3 10/16] treewide: Use struct_size() for vmalloc()-family Date: Thu, 31 May 2018 17:42:27 -0700 Message-Id: <20180601004233.37822-11-keescook@chromium.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601004233.37822-1-keescook@chromium.org> References: <20180601004233.37822-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(-)