Received: by 2002:a17:90a:37e8:0:0:0:0 with SMTP id v95csp7143449pjb; Wed, 16 Oct 2019 00:46:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlyqOgmAFswHjVDV/fjiov1wGcfAEQevS9Uq155/sR/cVSWNrWp7AR/sddB+HbCeqjTowr X-Received: by 2002:a50:e71a:: with SMTP id a26mr37485536edn.265.1571212004007; Wed, 16 Oct 2019 00:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571212004; cv=none; d=google.com; s=arc-20160816; b=Q/fT5RMla5UXK6im2vOx14a0MAph3vheS5J7bhgSs6In6qsWfJyRujfMsPRsrGllVL SMAH3xdHQpSuJ/05Z5Fwv8sMJov4ghRSsGSWjJYhuWIwO4SWm6beEia8aRN6aOOgTw9M +JHkE1UEV11DbyofJqKW08SI8p58cIEO8M28bfCCEOnbMw4gZdzc9Kn7XVuSecVj6OO5 wbUfCi5hA6hzfRCaciUbsgGlId4TAeohuR7PD+KYHiTMQdH3d9Effkv96WToAhPxN7Wk Quhkntu/1SLc5QMYLXbdWskrKnbKsHB4rRYHXjASBE/Y7/8Ldfch/XmLP0ycHIx/pbah 2V3Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dINtZoz6hrqdrw8fPrHitvOQv0KIwoq+y048zXgmUWU=; b=h95Mojc4cVtj6ft8iXtGlxfFIyCv89TVUIuS16AGnRFJVm9uZJYTWuIBbbDKLfjtUH 3j20/sSOjtaWqbnV80mOpYiGmd8t53vi8rsMtt0EEfnvFUqKdli6ULFw/xTfea2VAlJY iP2vT6YL0yRpk7peihOzgCyim02prtO/bq5cAeun4bj+I+sdfaMzRKzaPq6RSgC/ne/K 6eanVCiAsx87b3YJxwwSK9NS3/q12eUaEAedp4bnDVI7jM9r8ddxsGpIRMN5oo4A69uE taUGE6Kqe//uSNcNbm3Lnx6HYt+U2V55F/Ee14iLtcMwIuhXXWPpONan0EuZyLsjNsbG igjw== 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 l22si14381670ejr.149.2019.10.16.00.46.21; Wed, 16 Oct 2019 00:46:43 -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 S2390334AbfJPAlv (ORCPT + 99 others); Tue, 15 Oct 2019 20:41:51 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53357 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390302AbfJPAlt (ORCPT ); Tue, 15 Oct 2019 20:41:49 -0400 Received: from [213.220.153.21] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iKXNr-00065g-DZ; Wed, 16 Oct 2019 00:41:47 +0000 From: Christian Brauner To: christian.brauner@ubuntu.com Cc: ast@kernel.org, bpf@vger.kernel.org, daniel@iogearbox.net, kafai@fb.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, songliubraving@fb.com, yhs@fb.com, Aleksa Sarai Subject: [PATCH v2 2/3] bpf: use copy_struct_from_user() in bpf_prog_get_info_by_fd() Date: Wed, 16 Oct 2019 02:41:37 +0200 Message-Id: <20191016004138.24845-3-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016004138.24845-1-christian.brauner@ubuntu.com> References: <20191009160907.10981-1-christian.brauner@ubuntu.com> <20191016004138.24845-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In v5.4-rc2 we added a new helper (cf. [1]) copy_struct_from_user(). This helper is intended for all codepaths that copy structs from userspace that are versioned by size. bpf_prog_get_info_by_fd() does exactly what copy_struct_from_user() is doing. Note that copy_struct_from_user() is calling min() already. So technically, the min_t() call could go. But the info_len is used further below so leave it. [1]: f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper") Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: bpf@vger.kernel.org Acked-by: Aleksa Sarai Signed-off-by: Christian Brauner --- /* v1 */ Link: https://lore.kernel.org/r/20191009160907.10981-3-christian.brauner@ubuntu.com /* v2 */ - Alexei Starovoitov : - remove unneeded initialization --- kernel/bpf/syscall.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index b289ae747cae..45524089e15d 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2309,20 +2309,17 @@ 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; u32 ulen; int err; - err = bpf_check_uarg_tail_zero(uinfo, sizeof(info), info_len); + info_len = min_t(u32, sizeof(info), info_len); + err = copy_struct_from_user(&info, sizeof(info), uinfo, info_len); if (err) return err; - info_len = min_t(u32, sizeof(info), info_len); - - if (copy_from_user(&info, uinfo, info_len)) - return -EFAULT; info.type = prog->type; info.id = prog->aux->id; -- 2.23.0