Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp56636imm; Thu, 7 Jun 2018 13:44:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLJO196l6UWkrtbF9s8ndLESGEUI4/yvxYFARiUYJi5deiqyyv8btbz1qLiQr2RCp68XcnM X-Received: by 2002:a62:d6d2:: with SMTP id a79-v6mr3143762pfl.87.1528404287353; Thu, 07 Jun 2018 13:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528404287; cv=none; d=google.com; s=arc-20160816; b=fsmcLX4viNyEGxzDhI6TUf5gV+FoZHI8HhuvPhz1AhCLUJyU4Rp7gsxVObZ5z+JnLy l4B6jfmalVRqaoJOjzqYqMPwfCaVibLNe9JiBrnh8UVbaAgJqf7ziWMdV1S6ye+wDF+g rKjidHLZf15x83x5lkVZLzpa4WRQ3MPoNQPfRQtVnbkMH/jES/YZ1JfN3M0AzmDq26rj Xe9NK9w+nMJImobV5lV0lAQZYIzXGEyPCfHT+/DZjySlFqT6RhkKcSwYA5xop8nhFmFh GvqRJiVZypccN9ilPBuG7jX/ctTeiUfjElZ7xIpKl4qovSLcA4+jepEVD+dSu1XmIwF9 ZC3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=/xWR1vwVrfdBIqw2Rcw074r7x93eVC98mKlL4MKuScE=; b=gORAVRUT8JpektpJFgaXYlC1D+HGui8NJypM8Wgm31TkW5PQrKKdBZmgqmhgoJjyiG eC+QUuGe0os5n9dkpdzo9OVwr/4N9VMkDGX/VWBzMj2OLZKbcDXr/WouRrY3PHm2XDLg M4LU1gJvps3JzQo7NhZ156Z7qU2EG9q4boGeV2hCKA9vL/yqJxVN4PzJr2aCBV8I6LSG +WkAVzc57W9OGXAKDPWkvTNLn8Boie6ZHd1NG666kp0aVUuf1zH6kELpysslf+BqgPFU iS8rg0+8j41APApuk486w/ZB3Theh9hKitZMNkzLfexbW/Zk6y97WjWUqM1SfbMqIxGF Q43w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=h5EyTmow; dkim=fail header.i=@chromium.org header.s=google header.b=P3gwci+s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8-v6si10045498pgq.637.2018.06.07.13.44.33; Thu, 07 Jun 2018 13:44:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=h5EyTmow; dkim=fail header.i=@chromium.org header.s=google header.b=P3gwci+s; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932471AbeFGUnL (ORCPT + 99 others); Thu, 7 Jun 2018 16:43:11 -0400 Received: from mail-vk0-f67.google.com ([209.85.213.67]:46983 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753229AbeFGUnK (ORCPT ); Thu, 7 Jun 2018 16:43:10 -0400 Received: by mail-vk0-f67.google.com with SMTP id b134-v6so6882578vke.13 for ; Thu, 07 Jun 2018 13:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=/xWR1vwVrfdBIqw2Rcw074r7x93eVC98mKlL4MKuScE=; b=h5EyTmowB3NGJlqgu54/PnjN36yUrruwBQnD9aC8ca+6m7TVOxhb4JUNwOzajr4nwd fsVNJ7o9LgElAdEjOhAysMFg8ordjkZgh7cMw3Eit06cyxD35ceCPRtc0+KLyO4e3POg rPMtRzUrw7D0IQ11dDTWiMg//ixtpTnDvPm6H5wyOKYQy9vzWcAEpnqgL6aVMzEMSopY WYFVYDy6XbsUBYS2KaoIedyMeZ5Rsy3s9XLBOgFA0JT8gnTCRa4WS4Zpi32NNUOxp4k4 edAAhpv/xIGC0Ke8+Iv1EwLIu3X6g/giYyTh8SWQJx4cVFoScU6i7v46XU0PBBwaIRFp f+mw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=/xWR1vwVrfdBIqw2Rcw074r7x93eVC98mKlL4MKuScE=; b=P3gwci+skJTDm48GeJyK1Ff7JkH6bAI0xUGdjMD7O/3brbXVdI6JeeP9+KznPzJuvu QCszn7F8IZvshDIEnBb+4auWIVfJUDyw5Qpdr7+isaFlz+SDj7aJCB6CvYxK0BiHD0of 41W3nemkNbx2KGj/EsFNUXBG6mUSNDJybhg5A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=/xWR1vwVrfdBIqw2Rcw074r7x93eVC98mKlL4MKuScE=; b=rMWRNOzs2ssmUMCDaDO7KXG3qbYeHfhvdeQwgKuo1Z4/G5aWQ6weRJl4LB6cNWZ+P8 LAqol55QN3eYGHYsRvkMIlx5/SCA1OPjq2FFH6gc4QcEu3Ccx/61pr6vo3fRwqQrX83J y6jAMlhiJbIp45uSNsYBGsQ3o2PpdbsoSZ8JBySR2IjBRd2onsOs5dQjFKF5GN/rZhlA d2Dk9tFOfQo/3UeSekRMOIj5R/2/WVAqN4kuD0ZFx3Arh7vvEOw4LGPOMCGVJeOJWono dvB272UTUzPpEUTgRl58wO14pv5vyUVe5NFe+qLxhKXaG3IFmr2I39M4rAJS8d1rvZ8i bDBA== X-Gm-Message-State: APt69E1Bnhnq5CSQiM+vc0+aTr1AJtieDAr49mXTRMY/sF1db895IO+z EcTWGo8wpLurs2Qjv+HAoCfWOYPM9tulOU+5laV4RQ== X-Received: by 2002:a1f:5785:: with SMTP id l127-v6mr2239199vkb.84.1528404189025; Thu, 07 Jun 2018 13:43:09 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1f:a085:0:0:0:0:0 with HTTP; Thu, 7 Jun 2018 13:43:08 -0700 (PDT) In-Reply-To: References: <20180607145720.22590-1-willy@infradead.org> <20180607145720.22590-2-willy@infradead.org> From: Kees Cook Date: Thu, 7 Jun 2018 13:43:08 -0700 X-Google-Sender-Auth: P4bkQaUV3N0vCjIx4cqRMsPrdkE Message-ID: Subject: Re: [PATCH 1/6] Convert virtio_console to struct_size To: Matthew Wilcox Cc: Matthew Wilcox , Linux-MM , LKML , Kernel Hardening Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 7, 2018 at 12:29 PM, Kees Cook wrote: > On Thu, Jun 7, 2018 at 7:57 AM, Matthew Wilcox wrote: >> From: Matthew Wilcox >> >> Signed-off-by: Matthew Wilcox >> --- >> drivers/char/virtio_console.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c >> index 21085515814f..4bf7c06c2343 100644 >> --- a/drivers/char/virtio_console.c >> +++ b/drivers/char/virtio_console.c >> @@ -433,8 +433,7 @@ static struct port_buffer *alloc_buf(struct virtio_device *vdev, size_t buf_size >> * Allocate buffer and the sg list. The sg list array is allocated >> * directly after the port_buffer struct. >> */ >> - buf = kmalloc(sizeof(*buf) + sizeof(struct scatterlist) * pages, >> - GFP_KERNEL); >> + buf = kmalloc(struct_size(buf, sg, pages), GFP_KERNEL); >> if (!buf) >> goto fail; > > I feel like this one should have been caught by Coccinelle... maybe > the transitive case got missed? Regardless, I'll figure out how to > improve the script and/or take these. Oh, duh. Got it: "struct scatterlist" is not an expression, it's a type. I'll adjust the script, catch stragglers, and incorporate your patches. :) Thanks! -Kees -- Kees Cook Pixel Security