Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1127796ybp; Wed, 9 Oct 2019 09:10:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwbh6Q+DGveKASi+4Qlh1u+SHFYL1dx7S7kDj+M2PLqa+FQJ4H2g1tljSS6OTaX8MtJUhls X-Received: by 2002:a05:6402:657:: with SMTP id u23mr3712034edx.159.1570637426664; Wed, 09 Oct 2019 09:10:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570637426; cv=none; d=google.com; s=arc-20160816; b=G9eVLsxB2v0RZMjVtVPBKycIX+uj4C+7XNb5iP7NUgMlJqta2WG05DD0ttUIvfv7lF MohZdPFL04+k7ibYUDyjlJgK53+14Bafi1xHGk5xBxvdWkJiigEyZVxaXjfVPciDa3kK WFu+JaFgZryVq9ihDk4tj85sxeCEhrrbBMhcDe6q/yBCt9dovd/jAbzOPVQN9j6WdA6v 3oq9KgnPtqWNpa4hN4+ZBFWasYnzPOJFmpNT4WvFCBPnPngJ7Phk3nPgRkBVX/3dnHtc UNMe4Fs/SZtcQd/9e7BXf9P2MdMVGkaaMLgRErBJZPjY0NK4R3K5eAdarlUWo6iWPm89 Gsvg== 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=6AkVi+QzgoJ6peiQO0HYaEa9jrYF0V96jz5jteDwfJQ=; b=s4cjnnzFsGkmhfX6iQFH9uYyLVCWObe6xvPaQP3UPRuv3zM9Mpo1MBtqwtUrrqWUF6 XUT76pBuT31utCFJEhVmQ1GnpKfY2mYS4oAR3tfC/6pIOnQMjPxzA8azlurEdafbYPRA ai/W+Bz3f/2U7PdacPnxAugRLwJ/zE3OKgK28D2PO4KUfzfxt52NWBewDfZ9OzZj2olk LXW1T3qtCirD6MXQsEbP9zI58ACg4lEMirq9O4F6j0FqTyih+Ggjv/8QGipLB9T5YQDH gBbbfFnJhRIiDa0vQIgtkwZNPTlp6Cqafgi+Kbl5ejmnDXe3XtOBozkWatvUC98+84o3 Hh+Q== 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 n11si1436503ejb.240.2019.10.09.09.10.02; Wed, 09 Oct 2019 09:10:26 -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 S1731719AbfJIQJQ (ORCPT + 99 others); Wed, 9 Oct 2019 12:09:16 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:41921 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731226AbfJIQJQ (ORCPT ); Wed, 9 Oct 2019 12:09:16 -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 1iIEWX-00034Q-Hp; Wed, 09 Oct 2019 16:09:13 +0000 From: Christian Brauner To: Alexei Starovoitov , Daniel Borkmann , bpf@vger.kernel.org Cc: Martin KaFai Lau , Song Liu , Yonghong Song , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Christian Brauner Subject: [PATCH 2/3] bpf: use copy_struct_from_user() in bpf_prog_get_info_by_fd() Date: Wed, 9 Oct 2019 18:09:06 +0200 Message-Id: <20191009160907.10981-3-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009160907.10981-1-christian.brauner@ubuntu.com> References: <20191009160907.10981-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") Signed-off-by: Christian Brauner --- kernel/bpf/syscall.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 78790778f101..6f4f9097b1fe 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2312,13 +2312,10 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, 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