Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7128852ybp; Wed, 16 Oct 2019 04:19:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNMrAzSrVq8XLJDvuhskZluYv2AfxckvSSuSXyKxshdGW4qD2g2RJJaQ5Wf3R5tPgqWIQg X-Received: by 2002:a50:ec91:: with SMTP id e17mr37551881edr.169.1571224786516; Wed, 16 Oct 2019 04:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571224786; cv=none; d=google.com; s=arc-20160816; b=Cy3WwH6/Fzwg3gELN+NEkqeENjz00avHFo5ZUaMUHVt03zBR0c2aBr99N9BF99qG/m uTv/lHwmhCaA00mZ3Ps4bjXzuoxaAA5vz8Vmn/T/CeXDxz0lCfqKS1tQmGccwMyDUB8s /Khl9C1MPpBB63k6dar1Kg7/kbpnB2czJjdTBYTXNqMmFSMvZyipQzklcGtsiq7+UYGr +BlOQzkFHNcU7/IuZ7GyN7aueD3Ug2kP/ZH+iWnwV+0F1Nua85fyEBJc7KdUF0FPn5ME dPhKRjRoocfg82tHknvMuQhpAfliPprLZn7qrfDk3SG4Dk/HDtpVWgXz1k+waMha0iIS qTig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=/PW+sSSPQssp7Qm3IenbkRF16gX2p/tqWBpc3rsiFi8=; b=GB+JsFyhFIdZjIVLYMYwPNtHr0Jdoqm+Xd1jBo1WKm3PQmg2reJRIhoyPKqRP5+GVN inC4YUl2horOzL4uME7i0kjb4qjPkBXH8p2rrorT+j8/f9Yl0/9WbTO0kfO/B3kMgEr9 bEZog27yykazZ6umqJ36W5YbmLDmPg9EySnkC2gMDOwqQuyuqWoqEfTFOEbGF0MgQeXS MKP1mxaq0ZvFdJbdTbn3/xj29HA3PapdHCTnGrg9MSAwZzvScwfzMilys7M4qhlNhzYB C24gAIRgLjtAZxJf+RYsdhvRuBuiTRGvmnyZJa7PVcB3vkCpin91254VPon6X9/wDQbX DeOw== 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 r16si14857248edo.307.2019.10.16.04.19.23; Wed, 16 Oct 2019 04:19:46 -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 S2391016AbfJPDbV (ORCPT + 99 others); Tue, 15 Oct 2019 23:31:21 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:55449 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730211AbfJPDbU (ORCPT ); Tue, 15 Oct 2019 23:31:20 -0400 Received: from [213.220.153.21] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iKa1t-0008BG-Fb; Wed, 16 Oct 2019 03:31:17 +0000 Date: Wed, 16 Oct 2019 05:31:16 +0200 From: Christian Brauner To: Alexei Starovoitov Cc: Alexei Starovoitov , bpf , Daniel Borkmann , Martin KaFai Lau , LKML , Network Development , Song Liu , Yonghong Song Subject: Re: [PATCH v2 0/3] bpf: switch to new usercopy helpers Message-ID: <20191016033115.ljwiae2cfltbdoyo@wittgenstein> References: <20191009160907.10981-1-christian.brauner@ubuntu.com> <20191016004138.24845-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 15, 2019 at 07:14:42PM -0700, Alexei Starovoitov wrote: > On Tue, Oct 15, 2019 at 5:41 PM Christian Brauner > wrote: > > > > Hey everyone, > > > > In v5.4-rc2 we added two new helpers check_zeroed_user() and > > copy_struct_from_user() including selftests (cf. [1]). It is a generic > > interface designed to copy a struct from userspace. The helpers will be > > especially useful for structs versioned by size of which we have quite a > > few. > > Was it tested? > Either your conversion is incorrect or that generic helper is broken. > ./test_progs -n 2 > and > ./test_btf > are catching the bug: > BTF prog info raw test[8] (line_info (No subprog. zero tailing > line_info): do_test_info_raw:6205:FAIL prog_fd:-1 > expected_prog_load_failure:0 errno:7 > nonzero tailing record in line_infoprocessed 0 insns (limit 1000000) > max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 Ugh, I misrememberd what the helper I helped design returns. The fix is: diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 5db9887a8f4c..0920593eacd0 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -78,11 +78,8 @@ int bpf_check_uarg_tail_zero(void __user *uaddr, return 0; err = check_zeroed_user(uaddr + expected_size, rest); - if (err < 0) - return err; - - if (err) - return -E2BIG; + if (err <= 0) + return err ?: -E2BIG; return 0; } aka check_zeroed_user() returns 0 if non-zero bytes are present, 1 if no non-zero bytes were present, and -errno on error. I'll send a fixed version. The tests pass for me with this. Christian