Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2198100ybp; Thu, 10 Oct 2019 03:53:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIu/0zO3Qk8iW/ZmzdM10Itm2qRnIP27NvMa1+0pg7JVFsGaZNI/SimM1MWywoJXi2bkZM X-Received: by 2002:a50:f701:: with SMTP id g1mr7440239edn.62.1570704802711; Thu, 10 Oct 2019 03:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570704802; cv=none; d=google.com; s=arc-20160816; b=AP8WtRzw3W9x2OWO5Mu6mPQS6Pe5OSceQwvvDH/S+28aLW7rqGneIL7GtQl3uLCQwx KJTrFJDsitA1kkJN9NVG7FzZ9/gRXAH68CSB7+aFnkXVr+P6JVEwKAIV0uF9gcidMH8B 4TxuLVYX8nmqw+uX28Kyt4MtQUK1gujVmcICgYvCzF9Eae8SDEcUyiB21JE21TxnLuDm +nV+C/pe9l0Yd3d9sIE92j4YwnQQ4bT5+PwsB0cPX7Tsv9GECmHkQ5ZtyS1LqUbWM96u j2cKbCMpyl8q7DyjKjFnyVU+8xsGQC3kaxKYJcuzizu+E1TBhWJ1V/rs0+0Z0ts16cTu MA4A== 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; bh=2IfztzTK9u9SYCtoaIluqvKFXhBu2d9SyblmxsZh8U4=; b=nXO7/Ul+L75ehPRjqAGl7GKHZR7hv0aRsDpK4+2tJH2f4TnQXOqOIeCIPHL4SyoQKT p+TxF0O+XoP6XsGi+SWbnsc2alK+B2FRM20AZ6j3iFMzX/+7IjqdpJos0zux5mhi/8QW 8V6fZF2PMMaHprAxG+oPgW0qIcIEvsBPseuH9+uGTPAXbGGLZByyRU7jjKdQuMe035gB MgG+IwQarHGOueLkopcopwN7ha2uYnCExtJ1FAqzeNkB7qaItKvMD5Va4VbvmQC3EQtY Z9Jame/+N+FzsWP0rqiN38DLpB+zwtrITgnWacfxsNr9k1sAQkXxSGUx7xJVbVMH2aEG Wh6w== 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 pv13si2870249ejb.79.2019.10.10.03.52.59; Thu, 10 Oct 2019 03:53:22 -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 S1733045AbfJJKus (ORCPT + 99 others); Thu, 10 Oct 2019 06:50:48 -0400 Received: from mx2a.mailbox.org ([80.241.60.219]:31951 "EHLO mx2a.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbfJJKur (ORCPT ); Thu, 10 Oct 2019 06:50:47 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2a.mailbox.org (Postfix) with ESMTPS id 21E47A1A7B; Thu, 10 Oct 2019 12:50:45 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id oW1bKVSmI81Q; Thu, 10 Oct 2019 12:50:41 +0200 (CEST) Date: Thu, 10 Oct 2019 21:50:31 +1100 From: Aleksa Sarai To: Christian Brauner Cc: Alexei Starovoitov , Daniel Borkmann , bpf@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] bpf: use check_zeroed_user() in bpf_check_uarg_tail_zero() Message-ID: <20191010105031.eadc7baldnnufxjf@yavin.dot.cyphar.com> References: <20191009160907.10981-1-christian.brauner@ubuntu.com> <20191009160907.10981-2-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="yrlewcij3x6slscb" Content-Disposition: inline In-Reply-To: <20191009160907.10981-2-christian.brauner@ubuntu.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --yrlewcij3x6slscb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-10-09, Christian Brauner wrote: > 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. >=20 > [1]: f5a1a536fa14 ("lib: introduce copy_struct_from_user() helper") > Signed-off-by: Christian Brauner Acked-by: Aleksa Sarai > --- > kernel/bpf/syscall.c | 22 +++++++--------------- > 1 file changed, 7 insertions(+), 15 deletions(-) >=20 > 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 =3D min(expected_size, actual_size); > + size_t rest =3D max(expected_size, actual_size) - size; > int err; > =20 > if (unlikely(actual_size > PAGE_SIZE)) /* silly large */ > return -E2BIG; > =20 > - if (unlikely(!access_ok(uaddr, actual_size))) > - return -EFAULT; > - > if (actual_size <=3D expected_size) > return 0; > =20 > - addr =3D uaddr + expected_size; > - end =3D uaddr + actual_size; > + err =3D check_zeroed_user(uaddr + expected_size, rest); > + if (err < 0) > + return err; > =20 > - for (; addr < end; addr++) { > - err =3D get_user(val, addr); > - if (err) > - return err; > - if (val) > - return -E2BIG; > - } > + if (err) > + return -E2BIG; > =20 > return 0; > } --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --yrlewcij3x6slscb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSxZm6dtfE8gxLLfYqdlLljIbnQEgUCXZ8M9AAKCRCdlLljIbnQ Epr/AQCyrkQQbHuqCW5VkNaIJxIvHI5/ShmQM9ev+h5OCSYKvwEAhqXnMkhCZMnZ 6Y4CZGrZrNvytbxMMC7EDJEagjZPLQo= =MUrF -----END PGP SIGNATURE----- --yrlewcij3x6slscb--