Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp946466ybm; Fri, 29 May 2020 16:31:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0nrK2y+XRzyTgMheQX+GxOC4sMrDhTkU13X3unQlLKUcB+YQ/0NqJcvxeu3KmnDzZlSUU X-Received: by 2002:a17:906:5e08:: with SMTP id n8mr10008197eju.132.1590795064161; Fri, 29 May 2020 16:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590795064; cv=none; d=google.com; s=arc-20160816; b=zBBbXDTQ8fUbkox2R1d09LMOR7SIk6hVsDqwDv95LSV2MRj2ZWIyVzEaYL49Ha9UKP 0bCFuqOtDyH9Jn65Whla2xJwCX/RaXN80nfedwkcv1MSw1HnPyAnBAhoICeZHZ76QjLJ n1H55yt+8AB/IL1R2BhnP/ghxeG8XWelIQngbGsFxmPFWnMqXWQeMbaDQlrUu8lxpoSf yPgdRM+zkG0jM9Wwp4KMG8mI1l0BnQHNibVPNnZDwh1gKX/yTPFgLGhFY2FtCQQzORJf YqtviPtj+rl2WDV+PNBcduJnkTp6fZbuvDk9lfuErZFX9jtQsrfPOe5/QXPBUUwdtkKn u7Jw== 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=C95++3jTSdKgcNvcEymaJciNG5IGENjuCVDY7Ni3Ccg=; b=pm58XP2xssuwzSiJI0fyL61E8lLvZ8cnqVQVlstmYjIns4LuLQfo+nPcgJ2MEfjbI4 GOW328XvzkNCbYS2u4iiB83tJbvDzbwDYewtfRKCdRIi7TOC5qIXbtm8pBHS5w3WxcP2 bB/zklIM4v9nI1RWp4yArHJwS98GDWZahqGqHMck2hGdTFj5QB6gCKH5nt3AKUM8u4+3 Bv0EiRouEGI8X6xozAzwXEebpI73g8C3imZxCqzinlhJiwCmnCLVGGaIl3Goc4PdUdWi aHyQUuUPAPjXsPO52a+jmzVeWMw0I/LHHllOEc6snEcSYYs7qFgaAinwLhbCjSkDEyT3 f24A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr12si9080905ejc.352.2020.05.29.16.30.41; Fri, 29 May 2020 16:31:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728763AbgE2X2W (ORCPT + 99 others); Fri, 29 May 2020 19:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728738AbgE2X2Q (ORCPT ); Fri, 29 May 2020 19:28:16 -0400 Received: from ZenIV.linux.org.uk (zeniv.linux.org.uk [IPv6:2002:c35c:fd02::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 104E7C08C5CB; Fri, 29 May 2020 16:28:16 -0700 (PDT) Received: from viro by ZenIV.linux.org.uk with local (Exim 4.93 #3 (Red Hat Linux)) id 1jeoQA-000Bks-2G; Fri, 29 May 2020 23:28:14 +0000 From: Al Viro To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexei Starovoitov , bpf@vger.kernel.org Subject: [PATCH 9/9] bpf: make bpf_check_uarg_tail_zero() use check_zeroed_user() Date: Sat, 30 May 2020 00:28:14 +0100 Message-Id: <20200529232814.45149-1-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200528234025.GT23230@ZenIV.linux.org.uk> References: <20200528234025.GT23230@ZenIV.linux.org.uk> 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 From: Al Viro ... rather than open-coding it, and badly, at that. Signed-off-by: Al Viro --- kernel/bpf/syscall.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 64783da34202..41ba746ecbc2 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -67,32 +67,19 @@ 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; - int err; + unsigned char __user *addr = uaddr + expected_size; + int res; 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; - - for (; addr < end; addr++) { - err = get_user(val, addr); - if (err) - return err; - if (val) - return -E2BIG; - } - - return 0; + res = check_zeroed_user(addr, actual_size - expected_size); + if (res < 0) + return res; + return res ? 0 : -E2BIG; } const struct bpf_map_ops bpf_map_offload_ops = { -- 2.11.0