Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4625723imm; Sat, 25 Aug 2018 23:17:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbOA37nu8Ie+3c4Md6LXOyVIfvqguSSHgI1hFggrJZkaJq64hL8jus3h5S0i6WGXBNf2hcd X-Received: by 2002:a17:902:b189:: with SMTP id s9-v6mr8028538plr.188.1535264249814; Sat, 25 Aug 2018 23:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535264249; cv=none; d=google.com; s=arc-20160816; b=cI/Drfwrq2Z3BZ0ocsmxC5HTwIs2pyENVU8xmsC9WbMkoln0dsEM7w5aU9pdre8KFi Xgq4O+JmnNYHikoNinpJ4C02pysjrFqsQA6ebz3njDsieU3/8rx4X0DJGCe4IIaBwmin iVbsldfuWIml2pX90AfwnKTdkFDxKsF4kYqFLJf3aePyP+VOrK5MwHyCcEjrDIeD4z/A I2a7ucP/aMdzlzU4RtCYYflieE25gh5MwaD+8IALWwFmaSmlCO/Y4ZL262G2JZzRlcIr 6DsnexwMqLS7+yNFcCqEpImHDRc1WCw8D0uNNpHq9XSkQYDmlMow1tbaODWNji0pXsUW zjUg== 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:arc-authentication-results; bh=ujTE9K3aIQi3taLzAcKCjgBjk8ltA8Sqz60iNAFQSlc=; b=AyqEt+UeBeW02OPhOpWfuR0AI96d79n+qxuWoe9bviVi22oMeG44Av9YA9a8nvT6ms LAA8D8OA8VoeOHq+FVDoJ0FVN1/+s7ZIBhwGG613V2uI0X7/LqpssZ9xxqSQa9jQh0uk kiNhNY1mtqc1BL46zvRKrYpe862gn4MOpPrql+Ursm3p7p1UY9ua9akFOlJyvm+svs8C qFat9U/iOdPd3JCWawmGBvfTTf+tgDhec/pAUGJ3mEMsXitqqJ6ar53XCtmG1EZJQRwX RH8ygbbgpVEJMzcAoV/S6PzR/QRLob1hgE8jF3CYnuJAEdsT55OSspgz6KPYRFtEvIZJ nEZQ== 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 i21-v6si9383572pgg.513.2018.08.25.23.17.11; Sat, 25 Aug 2018 23:17:29 -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 S1726741AbeHZJ53 (ORCPT + 99 others); Sun, 26 Aug 2018 05:57:29 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:56088 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726324AbeHZJ53 (ORCPT ); Sun, 26 Aug 2018 05:57:29 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1ftoKt-0005c2-4u; Sun, 26 Aug 2018 06:15:46 +0000 Date: Sun, 26 Aug 2018 07:15:43 +0100 From: Al Viro To: Kees Cook Cc: linux-kernel@vger.kernel.org, Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , netdev@vger.kernel.org Subject: Re: [PATCH] net: sched: Fix memory exposure from short TCA_U32_SEL Message-ID: <20180826061534.GT6515@ZenIV.linux.org.uk> References: <20180826055801.GA42063@beast> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180826055801.GA42063@beast> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 25, 2018 at 10:58:01PM -0700, Kees Cook wrote: > Via u32_change(), TCA_U32_SEL has an unspecified type in the netlink > policy, so max length isn't enforced, only minimum. This means nkeys > (from userspace) was being trusted without checking the actual size of > nla_len(), which could lead to a memory over-read, and ultimately an > exposure via a call to u32_dump(). Reachability is CAP_NET_ADMIN within > a namespace. > > Reported-by: Al Viro > Cc: Jamal Hadi Salim > Cc: Cong Wang > Cc: Jiri Pirko > Cc: "David S. Miller" > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook > --- > This should go through -stable please, but I have left off the "Cc: > stable" as per netdev patch policy. Note that use of struct_size() > will need manual expansion in backports, such as: > sel_size = sizeof(*s) + sizeof(*s->keys) * s->nkeys; Saner approach would be sel_size = offsetof(struct tc_u32_sel, keys[s->nkeys])... > + 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);