Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1127411ybp; Wed, 9 Oct 2019 09:10:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTRRWYOQd2hyaidgKuSktsxD+9ylFX8Vu6HArpzX8wScz4e5VBSkXg/rZe4X4uy8t/G714 X-Received: by 2002:a17:906:2d49:: with SMTP id e9mr3563778eji.240.1570637407870; Wed, 09 Oct 2019 09:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570637407; cv=none; d=google.com; s=arc-20160816; b=jTMBBfge1SPajpS/udP7t/+Al+uNVxpirUkwX5zmbUr7BhKl5pvjngIqltcxRrlai8 D+hAq2gH8XE15hbT9o3be06Z4c+1OMU5kmW3c1v8pwUFA/WtkrLG41eCHdM1eI1vWN4S JtiXq57wiId/6lVS2/y/P6lojhY8A3+YhhGBIGLAAVUr8FkOYqSNKn9C+dtT48zjU6P8 BqojbloW/CQ8CEVFjCmIrwUNdsRUdbn3r2VcBbsJCeISWgCDfnGRY1p68nd13mSluhfA oSo6N8XiDjbIs/vS1Lghm7V5l0u44XVIiCYd//r2NL0kte5CpH7SF38F+4uNAp1iORgO fjug== 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=OulIqmmBFCZpUHAR9TnRM7EtAuNQwXPL92YJheg/zeE=; b=USE7+K1ajiGO/1Iirxt/NFrm19IT8GvqVbokYNecx37oVyCq8Y+AMtyKCg//V3SDRh F2/vDwrqAK8+bYqWhLYmC+N7cjDlkC8X9X9VrKq9vRAO07yqe9jskKMMa6ClV+MKFEzS OZUtI1bZ7YvPFmIFtpABwmTLb509eVQpqrZU65+kerhk+TAb1O+TZ0fanIlQrYyLa1sQ PCN/fN+2Z/eXoZiN+l602J2DlJivoVpUC43MAOHcmxngtE4rR2/Bi/MODqcnjaKgbAvP OaxfPsEceCT4SXaLApifgvWUe26RuGHEa8Z09t4jlVZN5E/8t3ik9VFtszw378ADGYlU Fqeg== 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 w34si1752493edc.252.2019.10.09.09.09.44; Wed, 09 Oct 2019 09:10:07 -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 S1731749AbfJIQJS (ORCPT + 99 others); Wed, 9 Oct 2019 12:09:18 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:41923 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731452AbfJIQJR (ORCPT ); Wed, 9 Oct 2019 12:09:17 -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-5J; 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 1/3] bpf: use check_zeroed_user() in bpf_check_uarg_tail_zero() Date: Wed, 9 Oct 2019 18:09:05 +0200 Message-Id: <20191009160907.10981-2-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]) check_zeroed_user() which does what bpf_check_uarg_tail_zero() is doing generically. We're slowly switching such codepaths over to use check_zeroed_user() instead of using their own hand-rolled version. [1]: f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper") Signed-off-by: Christian Brauner --- kernel/bpf/syscall.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 82eabd4e38ad..78790778f101 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -63,30 +63,22 @@ int bpf_check_uarg_tail_zero(void __user *uaddr, size_t expected_size, size_t actual_size) { - unsigned char __user *addr; - unsigned char __user *end; - unsigned char val; + size_t size = min(expected_size, actual_size); + size_t rest = max(expected_size, actual_size) - size; int err; if (unlikely(actual_size > PAGE_SIZE)) /* silly large */ return -E2BIG; - if (unlikely(!access_ok(uaddr, actual_size))) - return -EFAULT; - if (actual_size <= expected_size) return 0; - addr = uaddr + expected_size; - end = uaddr + actual_size; + err = check_zeroed_user(uaddr + expected_size, rest); + if (err < 0) + return err; - for (; addr < end; addr++) { - err = get_user(val, addr); - if (err) - return err; - if (val) - return -E2BIG; - } + if (err) + return -E2BIG; return 0; } -- 2.23.0