Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp725118imm; Thu, 13 Sep 2018 06:52:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbDmX48w2OWeZbw/Ymak+9fStdhswKJkxGJZev/dpCTmiX1ermqCgCTdiu/lWJU9NsUKrAW X-Received: by 2002:a63:9809:: with SMTP id q9-v6mr7196208pgd.58.1536846779485; Thu, 13 Sep 2018 06:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846779; cv=none; d=google.com; s=arc-20160816; b=AivjlEUvx1kTOBlRvsy8XzmxSMT98Gf7Tbp/6A345TMj50upHh6Qvrdynbp9P0cTK7 88RB2Tk98WWLqiFMS+CXnwuboHxG4zWPw7ssXTHAEuKL1uV/m1rMNiLRqnPM41YAZdLQ 1PY52DPUvD3GAoMqEHA8yZx6aOtV9CQvognNrRDQWBuCnG14ylWyrdIObW2twuPWtUNg dl8H37plLXfxf2BymmmMzxNHJwjFL7QSswcLA+AL91wWxG9cR/au2UtP7wQYmQyPpZnB c18Zyb3xHHnxfaUYPB9XOWwbld29vCMkzDZNkaj/OPZr0iCUygy9mZRTRHRlFe1g5qH7 2mkw== 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:message-id:date:subject:cc:to :from; bh=MSKKh2rOvqqcFRsbntoHcqWLVKUx+jy0AbtQZsDIhFI=; b=GS6HFHNQOElt/CnHamJ5WK54vCk5psAmfTsTsZJy5AQ00hUNa09lFoBEN/5Y0ObLI7 yM78wAPrlQtbYJ64jkcIFUlz+ENb7N43vMDXJ+D8dFsTaoxzAa6Bg3Gbs59IVtLZ5BTZ 2x1VthtkAjVBUVtDkljw1oEQMrt5Z2/gaK01ZOgO0ZZXMUTg+gtUntxGZWYmxsQa3dII waRIyVZih3UyMvollUwogs+QDyp8lU3LrfyLF6CGpuvBnQ0+KE/HoKKz/WejTWTU7LyV eMUkObHitAuyKheHzwhugz/dCIjuQZCRNp4WSSGw/CAiiDqN50YYC+ekHVTyWqfFpyEK KBGQ== 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 v4-v6si3933510pgn.110.2018.09.13.06.52.43; Thu, 13 Sep 2018 06:52:59 -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 S1730965AbeIMTB4 (ORCPT + 99 others); Thu, 13 Sep 2018 15:01:56 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33474 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730119AbeIMTBz (ORCPT ); Thu, 13 Sep 2018 15:01:55 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 96A96CDB; Thu, 13 Sep 2018 13:52:19 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , netdev@vger.kernel.org, Kees Cook Subject: [PATCH 4.18 005/197] net: sched: Fix memory exposure from short TCA_U32_SEL Date: Thu, 13 Sep 2018 15:29:14 +0200 Message-Id: <20180913131841.780508534@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook [ Upstream commit 98c8f125fd8a6240ea343c1aa50a1be9047791b8 ] 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 Acked-by: Jamal Hadi Salim Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sched/cls_u32.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -912,6 +912,7 @@ static int u32_change(struct net *net, s struct nlattr *opt = tca[TCA_OPTIONS]; struct nlattr *tb[TCA_U32_MAX + 1]; u32 htid, flags = 0; + size_t sel_size; int err; #ifdef CONFIG_CLS_U32_PERF size_t size; @@ -1074,8 +1075,13 @@ static int u32_change(struct net *net, s } s = nla_data(tb[TCA_U32_SEL]); + 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); if (n == NULL) { err = -ENOBUFS; goto erridr; @@ -1090,7 +1096,7 @@ static int u32_change(struct net *net, s } #endif - memcpy(&n->sel, s, sizeof(*s) + s->nkeys*sizeof(struct tc_u32_key)); + memcpy(&n->sel, s, sel_size); RCU_INIT_POINTER(n->ht_up, ht); n->handle = handle; n->fshift = s->hmask ? ffs(ntohl(s->hmask)) - 1 : 0;