Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp831309pja; Wed, 1 Apr 2020 09:30:03 -0700 (PDT) X-Google-Smtp-Source: APiQypIVChdWvePH0oHlYMSShI4p3dq3FBWORBzeUFIFezc7y529UpGW4ADfnfB1Y49i0HhW8gia X-Received: by 2002:aca:c506:: with SMTP id v6mr3571950oif.26.1585758602831; Wed, 01 Apr 2020 09:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585758602; cv=none; d=google.com; s=arc-20160816; b=Tamltg2PX3QVBIYEAUL+VazmU1gu9BuV+b6dodo0ATeZfe7P/zGt020tUMzrh0KB3k MAr5ONrOOiSiZjYOSw90bQcsUPxINaXigPM8x5PNb+ZuPvqd1I7quqGzlqycDC3swg5+ KmdybFgvNVXWd+3lkFJ/Ycfxbv1q4aVFVU4/QGSCHtqfWoREJNR6OPq6DWu3poWjDjba 7XWi/1yC7LcAnPP8RvUiHApiTad/3h8zJdGOxotH29FugM8HW93J0xiL8ylcDTuFZyof V3ugzq80JNee4tPGea5DFYfUCbVta0lgLuJbCXN166QgtuIE+ExUUoJWIQVV1516X3++ LTFg== 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:dkim-signature; bh=LJFLO03KPk9e6koLHQ7M4Pp2eOeCL3iWXuMDd2C78l0=; b=xFJwpvjC98xGZJpMmU5Ec3KgB68NDbFVVY1mstcNr2pcA7mF1gnX/xG29jemBhU4Sa +kVRS+lBuh+OakEXXsO8eBlENRamUahuF2hHXLRn30CHsDxnZBVSdR2KpeJND3pZWfXX bi20x7UqaxF77GTx0fp+xaj2phHnKxGup/2Xlf47jDOGgbrW8HJey7GymNg/q3yrWX46 l5mKi1h0ysiolk0j3xzyXBA0Io4qgNP8acNL1q4VF+GR1DM/CfgsM09gTPnefLKfg0IM pkswVAv1lsc036XCgACRFxrHVpw2VwzTxPv1fcmSSaJaeHV8x/I6k6HzAsOd+KpXpb3U cLgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="CDY/Vo+v"; 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 p3si1123293otk.62.2020.04.01.09.29.50; Wed, 01 Apr 2020 09:30:02 -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="CDY/Vo+v"; 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 S2387799AbgDAQ2S (ORCPT + 99 others); Wed, 1 Apr 2020 12:28:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:53468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387582AbgDAQ2M (ORCPT ); Wed, 1 Apr 2020 12:28:12 -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 7C59021582; Wed, 1 Apr 2020 16:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585758492; bh=w8IrY9r12WpYReH7DJwsZobqRrfkWlvu+9LYqSSptVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CDY/Vo+v27r6waFvVspuFPwEsSDxCtqv1h1eQkhGVzEBVEYwSbFdCmlwEryu0CfBq 739py7nK+jpxzwncrcKq5ST4oxuyZy/kf/t1IJ0hKedh/LLvE3hdY+TQvUtxAzj7HA IRez9A3TDDl/AG+XjgYMSj1a6Gn/jO/64HJclkK0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , Yonghong Song Subject: [PATCH 4.19 106/116] bpf: Explicitly memset some bpf info structures declared on the stack Date: Wed, 1 Apr 2020 18:18:02 +0200 Message-Id: <20200401161555.744987196@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161542.669484650@linuxfoundation.org> References: <20200401161542.669484650@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Greg Kroah-Hartman commit 5c6f25887963f15492b604dd25cb149c501bbabf upstream. 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 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Daniel Borkmann Acked-by: Yonghong Song Link: https://lore.kernel.org/bpf/20200320162258.GA794295@kroah.com Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/btf.c | 3 ++- kernel/bpf/syscall.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -2387,7 +2387,7 @@ int btf_get_info_by_fd(const struct 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; @@ -2396,6 +2396,7 @@ int btf_get_info_by_fd(const struct 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; --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1958,7 +1958,7 @@ static int bpf_prog_get_info_by_fd(struc 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; char __user *uinsns; u32 ulen; @@ -1969,6 +1969,7 @@ static int bpf_prog_get_info_by_fd(struc 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; @@ -2136,7 +2137,7 @@ static int bpf_map_get_info_by_fd(struct 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; @@ -2145,6 +2146,7 @@ static int bpf_map_get_info_by_fd(struct 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;