Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp869789ybb; Fri, 20 Mar 2020 09:23:40 -0700 (PDT) X-Google-Smtp-Source: ADFU+vscDaag2PnI/nnaav0xhx2iv+Z0whdLhL4u12xZ8PowoJWfVGZt6UL7ph2AtSk4jfC4gKCk X-Received: by 2002:aca:3b41:: with SMTP id i62mr6958551oia.55.1584721420466; Fri, 20 Mar 2020 09:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584721420; cv=none; d=google.com; s=arc-20160816; b=alBht0cCRSeG9nIGJoTJBkYpUZt9Vqu93XWCmPEIOTxsYLddACfDeGb1YAqhJ/Sgck MVbVR43P1sio1EW8G3iRIfvCM/Hd+HvL0hn4/bns7mdG7rSH7KWF5chnjIpWX0QTcR/r MyvStQsRwgZpOZkMiOmuxFiLfrXE/Z25gBXCFB8TzZogCGQYC1KLWom4raLGICaizfTN 9TmL1KkB+Mj7/B1+sM63XSY+I6p9M7LT7ZIg6KvF9HNVpk+GwPkMI+2TaJ8N7aImPOlI HL5AdTNEFncdmZ9CedPnqXYiusqZqzQTLeiVq+cMaMhrb2ExdI1EPaQerOZDB8S6MC7z 2mBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=5nmLxEE0NFdLXp3qDmKooEbihCMQ3h2bWTSCe4ACQ0s=; b=Z4Q8c9P3L7JzrViQh6JWHtTo4TPBMXNltJnkisa5TXO3rGG8pxDYr0BfHFHViJSJrS w+i+vWpqlNQRpuoUb4sGBx1IamRYbMIKP9+5FC3aopkpncMsrDpgnGOd8jBmKfQhakhT bajVmCbBCjGK4zdpWj47h0j5NBYBp6wEtLERESlTG5R9LCAGZ280D7T5YYPaG2xFW/9B h+2os5sYrajh7Rj/DGemWeaakiqLp+jPTRo/J0joD0/Q1KND68UgdCg0ct1embrycas0 joi+8iXqWIauM0lHHwBtQoNeimd6x/+V+pUfT1EOyV8k5RrBrHVYTm492yYUMmCKf2bX T0iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XfRCgcWX; 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 x66si3097455ota.244.2020.03.20.09.23.24; Fri, 20 Mar 2020 09:23:40 -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=@kernel.org header.s=default header.b=XfRCgcWX; 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 S1727415AbgCTQXB (ORCPT + 99 others); Fri, 20 Mar 2020 12:23:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727232AbgCTQXB (ORCPT ); Fri, 20 Mar 2020 12:23:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3FEC620724; Fri, 20 Mar 2020 16:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1584721380; bh=lv5dc5lyvfZeoMUgtuTZ8bzmyZe5g6+qYJhcqv6T9H4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XfRCgcWXuedy3Bn5EMaQ6y0SROMPmy3X3wmAmPLiGGByiiErxDcrSTbAmY3zZa11u AoJUJiP98hoo7XRqTS+oFm9IM31dcUfEOuACdITsJtOgO78KwrFbOefVfDdS8U7vpt OVJ91PgYCMQ9i+zWola632ATrMbJXHzucMJMPBuc= Date: Fri, 20 Mar 2020 17:22:58 +0100 From: Greg Kroah-Hartman To: Daniel Borkmann Cc: Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Maciej =?utf-8?Q?=C5=BBenczykowski?= , John Stultz , Alexander Potapenko , Alistair Delva Subject: [PATCH] bpf: explicitly memset some bpf info structures declared on the stack Message-ID: <20200320162258.GA794295@kroah.com> References: <20200320094813.GA421650@kroah.com> <3bcf52da-0930-a27f-60f9-28a40e639949@iogearbox.net> <20200320154518.GA765793@kroah.com> <20200320161515.GA778529@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200320161515.GA778529@kroah.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Trying to initialize a structure with "= {};" will not always clean out all padding locations in a structure. So be explicit and call memset to initialize everything for a number of bpf information structures that are then copied from userspace, sometimes from smaller memory locations than the size of the structure. Reported-by: Daniel Borkmann --- Note, this is separate from my previous patch, both are needed. kernel/bpf/btf.c | 3 ++- kernel/bpf/syscall.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 787140095e58..2fc945fcf952 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -4564,7 +4564,7 @@ int btf_get_info_by_fd(const struct btf *btf, union bpf_attr __user *uattr) { struct bpf_btf_info __user *uinfo; - struct bpf_btf_info info = {}; + struct bpf_btf_info info; u32 info_copy, btf_copy; void __user *ubtf; u32 uinfo_len; @@ -4573,6 +4573,7 @@ int btf_get_info_by_fd(const struct btf *btf, uinfo_len = attr->info.info_len; info_copy = min_t(u32, uinfo_len, sizeof(info)); + memset(&info, 0, sizeof(info)); if (copy_from_user(&info, uinfo, info_copy)) return -EFAULT; diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index a4b1de8ea409..84213cc5d016 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2787,7 +2787,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, union bpf_attr __user *uattr) { struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info); - struct bpf_prog_info info = {}; + struct bpf_prog_info info; u32 info_len = attr->info.info_len; struct bpf_prog_stats stats; char __user *uinsns; @@ -2799,6 +2799,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, return err; info_len = min_t(u32, sizeof(info), info_len); + memset(&info, 0, sizeof(info)); if (copy_from_user(&info, uinfo, info_len)) return -EFAULT; @@ -3062,7 +3063,7 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map, union bpf_attr __user *uattr) { struct bpf_map_info __user *uinfo = u64_to_user_ptr(attr->info.info); - struct bpf_map_info info = {}; + struct bpf_map_info info; u32 info_len = attr->info.info_len; int err; @@ -3071,6 +3072,7 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map, return err; info_len = min_t(u32, sizeof(info), info_len); + memset(&info, 0, sizeof(info)); info.type = map->map_type; info.id = map->id; info.key_size = map->key_size; -- 2.25.2