From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35855C74A54 for ; Thu, 11 Jul 2019 12:04:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04C4621537 for ; Thu, 11 Jul 2019 12:04:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kinvolk.io header.i=@kinvolk.io header.b="MHpOZCKs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728194AbfGKMEb (ORCPT ); Thu, 11 Jul 2019 08:04:31 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:39770 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728330AbfGKMEa (ORCPT ); Thu, 11 Jul 2019 08:04:30 -0400 Received: by mail-lf1-f65.google.com with SMTP id v85so3873592lfa.6 for ; Thu, 11 Jul 2019 05:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kinvolk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=fIJT5H6LYisrbd6vwnAbhttHQR+HPbOb2XK62GqS1Hw=; b=MHpOZCKskoCvtbYHgam0V9As0k81++UdVULTKLpyLcH1oU0/shthaJcSS97lvqKcN0 TZnB01QXcJlzmc3x0nZeh8A2YzQl6Q2zoct2ZDuOh5d3Waced04J6SZh7moU0lKXgPRj +6l+dCjwuoSz/iS3VYY953WTyZ9VZlCvXCvvY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=fIJT5H6LYisrbd6vwnAbhttHQR+HPbOb2XK62GqS1Hw=; b=svo/eNWC6MRmEmFvT1j4OI3eITUJBOtcxa3nE9i4SV/5vKuCeKtB/tV9I4YAu42vge Q/RS+7QJww7/6syNhJRXYhc5gsNYScorw8yZdw5mfx2B0cWHUFFFabVR9snRdWQjOv05 CAq96lHQu5C8P9TfP73e1Xa1B9b24ZxtE3pnhEp4/Hoo9pmQFQw3avmIc66yPylVb8GM MjiqLoyOjrBVtDneuQJGzxd88ItP5VswEDco5wKToiXkUrvhn8gerkSrb5B84Q+YfhxF m/kLLmLXAJnudboNaP7bRGsj+uYxU2w/tDiVxzkZY0NR52Ib1gWQIEnsdlxe3mMYq5N9 WriQ== X-Gm-Message-State: APjAAAVjnh7V7GFXsJLsT64nxeByJKP1WTpTx6UU82gmXlLZLLC65ZlA PYasK1HJH/Pr8PJD35O5RMQuJfi3llUhIalcVDKxsw== X-Google-Smtp-Source: APXvYqyp6HAj1kmAl16bL6nUdA74Usn2n5AVINcaqQABnMYNCnKpl0eo7NEGHvenOcxj4U35c+eZBEfsaPQlyc4rVQ4= X-Received: by 2002:ac2:47fa:: with SMTP id b26mr1661369lfp.82.1562846668240; Thu, 11 Jul 2019 05:04:28 -0700 (PDT) MIME-Version: 1.0 References: <20190708163121.18477-1-krzesimir@kinvolk.io> <20190708163121.18477-3-krzesimir@kinvolk.io> In-Reply-To: From: Krzesimir Nowak Date: Thu, 11 Jul 2019 14:04:17 +0200 Message-ID: Subject: Re: [bpf-next v3 02/12] selftests/bpf: Avoid a clobbering of errno To: Andrii Nakryiko Cc: open list , Alban Crequy , =?UTF-8?Q?Iago_L=C3=B3pez_Galeiras?= , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Networking , bpf , xdp-newbies@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Thu, Jul 11, 2019 at 1:52 AM Andrii Nakryiko wrote: > > On Mon, Jul 8, 2019 at 3:42 PM Krzesimir Nowak wro= te: > > > > Save errno right after bpf_prog_test_run returns, so we later check > > the error code actually set by bpf_prog_test_run, not by some libcap > > function. > > > > Changes since v1: > > - Fix the "Fixes:" tag to mention actual commit that introduced the > > bug > > > > Changes since v2: > > - Move the declaration so it fits the reverse christmas tree style. > > > > Cc: Daniel Borkmann > > Fixes: 832c6f2c29ec ("bpf: test make sure to run unpriv test cases in t= est_verifier") > > Signed-off-by: Krzesimir Nowak > > --- > > tools/testing/selftests/bpf/test_verifier.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testin= g/selftests/bpf/test_verifier.c > > index b8d065623ead..3fe126e0083b 100644 > > --- a/tools/testing/selftests/bpf/test_verifier.c > > +++ b/tools/testing/selftests/bpf/test_verifier.c > > @@ -823,16 +823,18 @@ static int do_prog_test_run(int fd_prog, bool unp= riv, uint32_t expected_val, > > __u8 tmp[TEST_DATA_LEN << 2]; > > __u32 size_tmp =3D sizeof(tmp); > > uint32_t retval; > > + int saved_errno; > > int err; > > > > if (unpriv) > > set_admin(true); > > err =3D bpf_prog_test_run(fd_prog, 1, data, size_data, > > tmp, &size_tmp, &retval, NULL); > > Given err is either 0 or -1, how about instead making err useful right > here without extra variable? > > if (bpf_prog_test_run(...)) > err =3D errno; I change it later to bpf_prog_test_run_xattr, which can also return -EINVAL and then errno is not set. But this one probably should not be triggered by the test code. So not sure, probably would be better to keep it as is for consistency? > > > + saved_errno =3D errno; > > if (unpriv) > > set_admin(false); > > if (err) { > > - switch (errno) { > > + switch (saved_errno) { > > case 524/*ENOTSUPP*/: > > ENOTSUPP is defined in include/linux/errno.h, is there any problem > with using this in selftests? I just used whatever there was earlier. Seems like is not copied to tools include directory. > > > printf("Did not run the program (not supported)= "); > > return 0; > > -- > > 2.20.1 > > --=20 Kinvolk GmbH | Adalbertstr.6a, 10999 Berlin | tel: +491755589364 Gesch=C3=A4ftsf=C3=BChrer/Directors: Alban Crequy, Chris K=C3=BChl, Iago L= =C3=B3pez Galeiras Registergericht/Court of registration: Amtsgericht Charlottenburg Registernummer/Registration number: HRB 171414 B Ust-ID-Nummer/VAT ID number: DE302207000