Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3152362ybc; Thu, 21 Nov 2019 04:11:57 -0800 (PST) X-Google-Smtp-Source: APXvYqy1gnTFy+EQ2FqJNwPYFvHtTQXD2D4qBu1TXigU/CozvabTaPff6lb1I83D7e/w7AwpD2kN X-Received: by 2002:a17:906:1d19:: with SMTP id n25mr13105288ejh.151.1574338317009; Thu, 21 Nov 2019 04:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574338317; cv=none; d=google.com; s=arc-20160816; b=Zp0OV0OQx6V3XTKF1Ht+/ZrL+I9lyNVm9gTpyQ6sXVezp/dYUo7dBNRSMFbe4Pzs0/ t/XClffBYPLteGq0UwK6xkjFkyMKD1y4/NeWXyJfPyapi3/d0HskIZwv4mjOv4N7O0/Z X3/Ka4AFh8vQZY5FqJDobl484ZVPnIANuUAVszFvpEKm3Ns7Tag2NWxtzKpztYKnVgOQ 1c9vPt61d9RfyoIGTHEZVtWtemKRJHf6btXWFYkTiojAX6/SHbXa77PWvzL62GLTfYbc lbmfAmSUEIVaIoc0/13rE9b7Gvtt9FzN58o8zYjTW/AzqajD6/XxQeVjkozZJ3F+AyOA 9EsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Dq2dMuOCLQfRiUH1NYttnwcL5/6LTvSWv74kK3octXc=; b=TCS/coR77PI1hEPj/Jy/68Hamr7pZGHPKA8xaNA7WdLusFI2JVkf6xyZ/sayry4aHJ N9xVxoRn5Qeod0U9Z5QmydsvPCMeAyO0gm/t8tlOLwJL0pvrceJbeSn8WIXnUHMid2+V qWokmtNFoQaqdEn5haxWq1p+Gi2m2S1toy/KuNZg4ohKOI3Z1H6byurOS8bTL1Owba51 t8OObVQF9nXC1euRhZVWp4dJPIOPbENC70kIeocHYB0KpNLND3OHTIVfAgK2Au+Q64iz 0XE5cfY9klQIfTb8lrT5iPjij1NQe42v8N8Z8D2kx41xa4Fq58UpLWtruCg+HvoJixFm MNig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=IQ4v7puY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x12si81327eju.50.2019.11.21.04.11.31; Thu, 21 Nov 2019 04:11:56 -0800 (PST) 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=pass header.i=@oracle.com header.s=corp-2019-08-05 header.b=IQ4v7puY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbfKUMKd (ORCPT + 99 others); Thu, 21 Nov 2019 07:10:33 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:48768 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbfKUMKd (ORCPT ); Thu, 21 Nov 2019 07:10:33 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xALC91JV013371; Thu, 21 Nov 2019 12:09:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2019-08-05; bh=Dq2dMuOCLQfRiUH1NYttnwcL5/6LTvSWv74kK3octXc=; b=IQ4v7puYKBsqJf7LIh7pGx2BQCJtML1CYnkjnmUFHpDVuxslvk7uZcZC4RygdqRqAPVB QJfB+ZRJe5qjGoKFJyySfdM68kKszk0q7Oe3b34iP4scY+QxypbF9B3lSInrF4ZT5w+B s9q7hxIVNqcI4XmxEPntgd38OPJDn7T8wwkis0rBPltN8Ypac3YzmPLeyqTHnOXNlMf1 KP2mF62PjYGlo0SSt8LRuv3UQm40cw6QHxBthKHq7H+kh1q5HPYVsF1EptgXp1FrVmKu lbdd0qZn8GgihIjSgcyQYaK5ycZ4DaIeV1uMTkReQHF6sKbHCSCkF9F/iy1vI6K2seMZ SA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2wa9rqunpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Nov 2019 12:09:07 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xALC8wCC040000; Thu, 21 Nov 2019 12:09:06 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2wdfrsanm3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Nov 2019 12:09:06 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xALC7x6X026371; Thu, 21 Nov 2019 12:07:59 GMT Received: from kadam (/41.210.154.230) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 21 Nov 2019 04:07:57 -0800 Date: Thu, 21 Nov 2019 15:07:33 +0300 From: Dan Carpenter To: Michal Kubecek Cc: "Enrico Weigelt, metux IT consult" , Joe Perches , zhanglin , davem@davemloft.net, cocci , Andrew Morton , Thomas Gleixner , Linus Torvalds , jakub.kicinski@netronome.com, ast@kernel.org, jiang.xuexin@zte.com.cn, f.fainelli@gmail.com, daniel@iogearbox.net, john.fastabend@gmail.com, lirongqing@baidu.com, maxime.chevallier@bootlin.com, vivien.didelot@gmail.com, wang.yi59@zte.com.cn, hawk@kernel.org, arnd@arndb.de, jiri@mellanox.com, xue.zhihong@zte.com.cn, natechancellor@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linyunsheng@huawei.com, pablo@netfilter.org, bpf@vger.kernel.org Subject: Re: [Cocci] [PATCH] net: Zeroing the structure ethtool_wolinfo in ethtool_get_wol() Message-ID: <20191121120733.GF5604@kadam> References: <1572076456-12463-1-git-send-email-zhang.lin16@zte.com.cn> <20191121111917.GE29650@unicorn.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191121111917.GE29650@unicorn.suse.cz> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9447 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1911210111 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9447 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-1911210111 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 21, 2019 at 12:19:17PM +0100, Michal Kubecek wrote: > On Thu, Nov 21, 2019 at 11:23:34AM +0100, Enrico Weigelt, metux IT consult wrote: > > On 26.10.19 21:40, Joe Perches wrote: > > > On Sat, 2019-10-26 at 15:54 +0800, zhanglin wrote: > > >> memset() the structure ethtool_wolinfo that has padded bytes > > >> but the padded bytes have not been zeroed out. > > > [] > > >> diff --git a/net/core/ethtool.c b/net/core/ethtool.c > > > [] > > >> @@ -1471,11 +1471,13 @@ static int ethtool_reset(struct net_device *dev, char __user *useraddr) > > >> > > >> static int ethtool_get_wol(struct net_device *dev, char __user *useraddr) > > >> { > > >> - struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL }; > > >> + struct ethtool_wolinfo wol; > > >> > > >> if (!dev->ethtool_ops->get_wol) > > >> return -EOPNOTSUPP; > > >> > > >> + memset(&wol, 0, sizeof(struct ethtool_wolinfo)); > > >> + wol.cmd = ETHTOOL_GWOL; > > >> dev->ethtool_ops->get_wol(dev, &wol); > > >> > > >> if (copy_to_user(useraddr, &wol, sizeof(wol))) > > > > > > It seems likely there are more of these. > > > > > > Is there any way for coccinelle to find them? > > > > Just curios: is static struct initialization (on stack) something that > > should be avoided ? I've been under the impression that static > > initialization allows thinner code and gives the compiler better chance > > for optimizations. > > Not in general. The (potential) problem here is that the structure has > padding and it is as a whole (i.e. including the padding) copied to > userspace. While I'm not aware of a compiler that wouldn't actually > initialize the whole data block including the padding in this case, the > C standard provides no guarantee about that so that to be sure we cannot > leak leftover kernel data to userspace, we need to explicitly initialize > the whole block. GCC will not always initialize the struct holes. This patch fixes a real bug that GCC on my system (v7.4) regards, dan carpenter