Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1088514ybg; Sat, 26 Oct 2019 12:41:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzr1NtPTnSDwA2gzg7/hxe66kXSsA6Q+K9b7pzn163+zsLQW5VGjfTrt5ufzTKDi3uqFUQZ X-Received: by 2002:a50:ac1c:: with SMTP id v28mr11244354edc.156.1572118909896; Sat, 26 Oct 2019 12:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572118909; cv=none; d=google.com; s=arc-20160816; b=fzcGHghsR3rMFCfxs/hAia8C1bgCDkF/o30c55SyCAitTnvtAUBi6ssvAcSe8thm4q J163Libdr1VEbIe+sXslOEY2ikCWC2EFKTGo0hq2SxuVpFk3Qnv3R7Vv5LDltuNrW9rx e0mNuYdHFOA0sOvW8GzL350VnDwINGipzcUZjeK+bWq/Z1tlvJKw+muCR2NFNkL280aa cH5WkyeyfxCSyeUyqo8JelgpNeWrPkxUWpfZHjhsq8gjXg3m4bAMY94AAbfOixhcJW33 yIntjaC8TUhDWvCDdtWtFiz+SKTHSxg+NEoxoD/wHpzw7+NQzog4s2r9m2DtIwpcNPL4 Bhug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=nI2h5u5NG9dgV5P+KSTodYUzBXUIs6BOxySuVZwpdOo=; b=U0QmdxrB+kqKjIQ7K8GQ5rphdJHLTinawiUkRHpA+GJslQjG9O0X1Iquen+E4V/mp8 dugSB+arNrblu1gO59ks5EUiao6cz7makxWSaZO55KDDKtYhDVn0RnThnm3tgYEPN7Ur HrN72SmhPUQJl9pFhub2p93I8I6DEpf1Z3ohrii/H6ehRjgzKV2Cq9PbLbhY3xT6DwJQ RN7xQTPdYxJjE0d5qv0r/zC5qKIhUCQ/LiyAt/N/A+SBc08GKQNeabbQYk3dSxyx62DN bgq8gAJDUdNRPQwOCwFwad8E+Hz+uTK0XsjzidpH6O7IN/dCzcsbxUCsBZn8Lzk+hvip Zjpg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q18si4195041eda.291.2019.10.26.12.41.12; Sat, 26 Oct 2019 12:41:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726473AbfJZTkd (ORCPT + 99 others); Sat, 26 Oct 2019 15:40:33 -0400 Received: from smtprelay0186.hostedemail.com ([216.40.44.186]:42911 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726342AbfJZTkd (ORCPT ); Sat, 26 Oct 2019 15:40:33 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id 3C59D180357D1; Sat, 26 Oct 2019 19:40:31 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:599:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3150:3353:3622:3653:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6119:6742:6743:7903:10004:10044:10400:10848:11026:11473:11658:11914:12043:12048:12049:12296:12297:12740:12760:12895:13161:13229:13439:14096:14097:14181:14659:14721:21080:21324:21451:21627:21939:30029:30051:30054:30091,0,RBL:47.151.135.224:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: stone20_785fe5ad57825 X-Filterd-Recvd-Size: 3871 Received: from XPS-9350.home (unknown [47.151.135.224]) (Authenticated sender: joe@perches.com) by omf12.hostedemail.com (Postfix) with ESMTPA; Sat, 26 Oct 2019 19:40:27 +0000 (UTC) Message-ID: Subject: Re: [PATCH] net: Zeroing the structure ethtool_wolinfo in ethtool_get_wol() From: Joe Perches To: zhanglin , davem@davemloft.net, cocci , Andrew Morton , Thomas Gleixner , Linus Torvalds Cc: ast@kernel.org, daniel@iogearbox.net, jakub.kicinski@netronome.com, hawk@kernel.org, john.fastabend@gmail.com, mkubecek@suse.cz, jiri@mellanox.com, pablo@netfilter.org, f.fainelli@gmail.com, maxime.chevallier@bootlin.com, lirongqing@baidu.com, vivien.didelot@gmail.com, linyunsheng@huawei.com, natechancellor@gmail.com, arnd@arndb.de, dan.carpenter@oracle.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, xue.zhihong@zte.com.cn, wang.yi59@zte.com.cn, jiang.xuexin@zte.com.cn Date: Sat, 26 Oct 2019 12:40:23 -0700 In-Reply-To: <1572076456-12463-1-git-send-email-zhang.lin16@zte.com.cn> References: <1572076456-12463-1-git-send-email-zhang.lin16@zte.com.cn> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.34.1-2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? There are ~4000 structs in include/uapi and there are ~3000 uses of copy_to_user in the tree. $ git grep -P '\bstruct\s+\w+\s*{' include/uapi/ | cut -f2 -d" "|sort|uniq|wc -l 3785 $ git grep -w copy_to_user|wc -l 2854 A trivial grep and manual search using: $ git grep -B20 -w copy_to_user | grep -A20 -P '\bstruct\s+\w+\s*=\s*{' shows at least 1 (I didn't look very hard and stopped after finding 1): include/uapi/linux/utsname.h:struct oldold_utsname { include/uapi/linux/utsname.h- char sysname[9]; include/uapi/linux/utsname.h- char nodename[9]; include/uapi/linux/utsname.h- char release[9]; include/uapi/linux/utsname.h- char version[9]; include/uapi/linux/utsname.h- char machine[9]; include/uapi/linux/utsname.h-}; and kernel/sys.c- struct oldold_utsname tmp = {}; kernel/sys.c- kernel/sys.c- if (!name) kernel/sys.c- return -EFAULT; kernel/sys.c- kernel/sys.c- down_read(&uts_sem); kernel/sys.c- memcpy(&tmp.sysname, &utsname()->sysname, __OLD_UTS_LEN); kernel/sys.c- memcpy(&tmp.nodename, &utsname()->nodename, __OLD_UTS_LEN); kernel/sys.c- memcpy(&tmp.release, &utsname()->release, __OLD_UTS_LEN); kernel/sys.c- memcpy(&tmp.version, &utsname()->version, __OLD_UTS_LEN); kernel/sys.c- memcpy(&tmp.machine, &utsname()->machine, __OLD_UTS_LEN); kernel/sys.c- up_read(&uts_sem); kernel/sys.c: if (copy_to_user(name, &tmp, sizeof(tmp))) where there is likely 3 bytes of padding after 45 bytes of data in the struct.