Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5093259imm; Sun, 26 Aug 2018 10:32:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbWXDXKIlFajhybK1DM8qE1XNYwqkjOvduIWW++hUyg6rbiG9WEjCgd3S8H+526BeCwyBHT X-Received: by 2002:a63:d345:: with SMTP id u5-v6mr9320043pgi.330.1535304747575; Sun, 26 Aug 2018 10:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535304747; cv=none; d=google.com; s=arc-20160816; b=ofYBKX0wg/kolQm0ng3CHHDC70AC6ya2KUP873QoLi+K7B9RxxHX1fYKRy7iaE+Xji HA+1/1jeVayTMUOBDjk4MQhBoh0/7Ek2DgzxjEu7sY4ybaOXav2//WXkmv6QEoA5mUfY yzjsKfgvDRdUrTSQ3BuvjP3uLAv15WREe9l2BcNJwof7BkMd0S644jEREXZUgYt8yJ8j wUe5f/HPWbqmdxcF61wwKQ/ybVm5MV4iW+NF8VVj0rsZDb5g/gkn79zOk/pEJs6mH8XL hp5eUeeHFZCkOpRbvyNY+3Tc3U2ixDbFCVEwvTfVg4KJJW/pFFR33z25Xa39ZkHtFqSd fLUA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=p35wbnf0hub1pz1s3tWmbzvPN9oPVtbqV0rGTXBjSHc=; b=FdOXGGDlK19LohqsWSIdJIFRbhGBWH6M1v51G6lh485PU5uI2Hi3bQeBNHrc56mrXy luBIBpirMIgIuMduh3ppxcWkBAnmD9nMaNFGhhoXWayE1MzxGAMxMxA4rgLarlvSy8G2 DOLPwdSH3hVk3E9KNgSAmOzryu0uKppOwYej9jsfjxaYbsY6+fVKeOffZBUCd/QBHUCk BD+Eybq5iwx9zp2WP0456Yb00XxOuMTMhBEIuKQ4NJU2vqYb6K2juMOJ30WC5Rd8RuhC FSeny+FAwgc7xccOF9XnjWp95/yTvHLyfJ3E7mKRx3tBSafrEkZUrBOYeeQtYmDLEOc0 5F7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mojatatu-com.20150623.gappssmtp.com header.s=20150623 header.b=ZRNz8kAH; 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 a17-v6si12009599pgb.369.2018.08.26.10.32.11; Sun, 26 Aug 2018 10:32:27 -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=pass header.i=@mojatatu-com.20150623.gappssmtp.com header.s=20150623 header.b=ZRNz8kAH; 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 S1726851AbeHZVOM (ORCPT + 99 others); Sun, 26 Aug 2018 17:14:12 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:45590 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbeHZVOM (ORCPT ); Sun, 26 Aug 2018 17:14:12 -0400 Received: by mail-io0-f195.google.com with SMTP id e12-v6so10976758iok.12 for ; Sun, 26 Aug 2018 10:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=p35wbnf0hub1pz1s3tWmbzvPN9oPVtbqV0rGTXBjSHc=; b=ZRNz8kAHOi0zwQgE49h167niBj09UhhuVeQi9KaL15VX79/rtb9BZvBgvL3soih1JR AAnx/UX5L9sOf6NMIiRDyQ+7LdZ5HY6vEBaPL1i56bGgpiGk3kBKHE2qb+2gWPZhAvkm Rq6ybTCgtzCSj5DPeN9NcmoMbiVXREjd3aNamwug1l15IW1wPafkpMwwF6ubHOPspdmW UonyUm8IS9cWAR3ux9Y+31OfUPeSGQEK59Qofi2CA1E5Fheq2VSBefb1N0meHHrAPXct Wv/zIclWKqPbX7YfpH3scqkuPvU/Pr6BH2FOoG3j+IHtKsZyafkvylTK3PKurtlW5D00 ZGNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=p35wbnf0hub1pz1s3tWmbzvPN9oPVtbqV0rGTXBjSHc=; b=NICVnQMyieGH12jFIWuZXNVsBQBMHl8YburGM+V6C4LUxdntSA0Tl+Xfv1BeZR6wvQ iXewn7SzG9wQ/eq5UXa9EvB4ICJhbDtliq73WGN36slVo+I0PDxKR/0nZhtuhYpyiCzj v4QIVEdzZ7Y27AoUowt2NMVtp5yxbj+vPI3wvPhGL5KCYHKEUKdY46B0pFfBhcCrIy9a tVZ5ovnoROMsi6GuXLFgYIvUBSZhewCyD7BxJsX7Wo9haD0O0eTf397lI77ofRqnDvIQ CauxljD6kj8T/d3XYUg6k+vidWf0Q4lhGjaPJQAwYgAd5GtpvFt50hDCNYUtgpQa72dX Uqgg== X-Gm-Message-State: APzg51CyNiseUscHNt/vBHCFa36fz57ct0MdWvkyIMgjZZY5mu6vgCGM U2AG/2uyIlFMM2SO874tsNvDGw== X-Received: by 2002:a6b:928b:: with SMTP id u133-v6mr7713478iod.296.1535304661888; Sun, 26 Aug 2018 10:31:01 -0700 (PDT) Received: from [10.0.0.129] (198-84-205-232.cpe.teksavvy.com. [198.84.205.232]) by smtp.googlemail.com with ESMTPSA id f24-v6sm4239875ioc.52.2018.08.26.10.30.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Aug 2018 10:31:00 -0700 (PDT) Subject: Re: [PATCH] net: sched: Fix memory exposure from short TCA_U32_SEL To: Kees Cook , Al Viro Cc: LKML , Cong Wang , Jiri Pirko , "David S. Miller" , Network Development References: <20180826055801.GA42063@beast> <20180826061534.GT6515@ZenIV.linux.org.uk> From: Jamal Hadi Salim Message-ID: <5c88b08d-b9ca-f3df-ae78-cf685ee6723a@mojatatu.com> Date: Sun, 26 Aug 2018 13:30:34 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-08-26 2:19 a.m., Kees Cook wrote: > On Sat, Aug 25, 2018 at 11:15 PM, Al Viro wrote: >> On Sat, Aug 25, 2018 at 10:58:01PM -0700, Kees Cook wrote: >> Saner approach would be sel_size = offsetof(struct tc_u32_sel, keys[s->nkeys])... > > Either is fine by me. > >>> + sel_size = struct_size(s, keys, s->nkeys); >>> + if (nla_len(tb[TCA_U32_SEL]) < sel_size) { >>> + err = -EINVAL; >>> + goto erridr; >>> + } >>> >>> - 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* Looks good to me. We should add an nla_policy later. Acked-by: Jamal Hadi Salim cheers, jamal