Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5149177imm; Sun, 26 Aug 2018 11:59:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZQDjr29VmMKSzI4gCVxfCpTkyatFtphmviyRjhZJgjmU6Qag/sU7uNgDKTCxcC7xTcvjxF X-Received: by 2002:a17:902:e183:: with SMTP id cd3-v6mr9992161plb.305.1535309968671; Sun, 26 Aug 2018 11:59:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535309968; cv=none; d=google.com; s=arc-20160816; b=eN66F5yeIrzGnDQwyend2ZMUBv4hWHsLGYpd7jht1eoDPGZ3FLU/ZNW5wKfjqwvEqn O+PsEK2IlPf5agAcLgdE6QZHHGNwJXru2GKcNK8EA3gi59LQcIlyskZkYr6m8hipyUac zIqS+DHBIIoSpsZBdLf1DK2h6OkDhsTbOFV8Y8Ign9DPDkO4QCRNlG6mfGELwAXwHSA8 BqL2GVwex7aSjrRuKIYpavg1o0dB0im0l5rXcHytseVHfPR/if7/MxcE+Sn+QUTXMJtz ninMQZCrX8FDauJMa0RjDDDzpf0MO4Bqg9tJMTvAzaxCtlvmDeHDBUb0VtpcrlHkRqQT I3yQ== 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 :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=2B5ndFj0s/2aYZLczd1TmOTjkjTsi0KLl0CSyhvSSAU=; b=ERuc+zwiaOWXSKavkGKlh2UMiR0bGkC1D5vKa/fg7kSoC9YMxE/DwsZZLVuV5etM+X N8VgFY8ZrT/9pDO0zrbqydfYt/h5XaWLp57onj0r7qlGy4z9sga1AwC2FyFi05qNjg8v nO+1UPGrsgtO+Eqf72fqWlQ492IRhl77JCpKMi39U9toDGw/F2zVksIaaKWv18rl4CoB TYPqzC5LGYjSDNZPbQbs/tfuiMkvbwqQyrnyQ3bmQwWJ8WSlTNIP/RCVD9L9mIMcC5z3 Vp+6myS6F5YBrqkbu4Ny+EkkGE4X/sIXsxp3D2cp60JimumxRqGUwdbbevodgQrkD8Oe cyLw== 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 r7-v6si13072217pli.248.2018.08.26.11.59.11; Sun, 26 Aug 2018 11:59:28 -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 S1726883AbeHZWlY (ORCPT + 99 others); Sun, 26 Aug 2018 18:41:24 -0400 Received: from smtprelay0029.hostedemail.com ([216.40.44.29]:57241 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726694AbeHZWlY (ORCPT ); Sun, 26 Aug 2018 18:41:24 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay05.hostedemail.com (Postfix) with ESMTP id A1C8B1802EB3D; Sun, 26 Aug 2018 18:58:00 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:355:379:541:599:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4385:4605:5007:6119:7903:7904:10004:10400:10848:11232:11658:11914:12296:12740:12760:12895:13069:13311:13357:13439:14096:14097:14181:14659:14721:21080:21324:21433:21627:30006:30054:30090:30091,0,RBL:47.151.153.53:@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:28,LUA_SUMMARY:none X-HE-Tag: sand37_7ff35e033381d X-Filterd-Recvd-Size: 2598 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf05.hostedemail.com (Postfix) with ESMTPA; Sun, 26 Aug 2018 18:57:59 +0000 (UTC) Message-ID: Subject: Re: [PATCH] net: sched: Fix memory exposure from short TCA_U32_SEL From: Joe Perches To: Al Viro , Kees Cook Cc: LKML , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Network Development Date: Sun, 26 Aug 2018 11:57:57 -0700 In-Reply-To: <20180826173236.GU6515@ZenIV.linux.org.uk> References: <20180826055801.GA42063@beast> <20180826061534.GT6515@ZenIV.linux.org.uk> <20180826173236.GU6515@ZenIV.linux.org.uk> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.28.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 Sun, 2018-08-26 at 18:32 +0100, Al Viro wrote: > On Sat, Aug 25, 2018 at 11:19:30PM -0700, Kees Cook wrote: > > > > - n = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key), GFP_KERNEL); > > > > + n = kzalloc(offsetof(typeof(*n), sel) + sel_size, GFP_KERNEL); > > > > > > ITYM > > > n = kzalloc(offsetof(struct tc_u_common, sel.keys[s->nkeys]), GFP_KERNEL); > > > > I prefer to reuse sel_size and keep typeof() to keep things tied to > > "n" more directly. *shrug* > > This is rather search-hostile, though. Fresh example from the same > area: where are struct tcf_proto instances created? Is it true that > each is followed by ->ops->init()? Is it true that ->ops->init() > is never called twice for the same instance? Is it true that > ->ops->destroy() is called exactly once between successful ->ops->init() > and freeing the object? > > That's precisely the kind of questions you end up asking when learning > a new area. Your variant makes those harder to answer; it does make > it easier to catch local problems on casual grep, but it's hell both > on the newbies trying to make sense of an area and on the old hands > from different areas. > > That, BTW, is why I hate the use of sizeof(*p) in kmalloc, etc. > arguments. typeof is even worse in that respect. True. Semantic searches via tools like coccinelle could help here but those searches are quite a bit slower than straightforward greps.