Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9776289ybi; Wed, 10 Jul 2019 16:56:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFW6t2bvHoyUhmBQ2reNnKLaF2qHuZ004LGIs/8I+iimgZvRJolnbXD76p6J3tzbG0wl++ X-Received: by 2002:a17:90a:32c7:: with SMTP id l65mr1186706pjb.1.1562802974616; Wed, 10 Jul 2019 16:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562802974; cv=none; d=google.com; s=arc-20160816; b=bnKK1F6iKBnJviqBA3Wntiw+aXbdP2XVWsHerpRIoBNXKoqxlqbVd5UtBmd9XivDa3 QIn9JDafInN3tH9vDtRdA+NpiDkr1TEuz/l3YCQfTn2+4apQ6w/ncK/x9x9jChz9sJr+ YhIgZBHa+gddUvR+zJSx3bhpv039ZwwxmOG63PvVx9AeOktzBx+prjEu3E2PC49f99Su UYU9vBkbL8IU2EfC28i/RybjPAwlgLMMyLXJfd9HGo7JPrYeXh1Ypo6XQfldBXarciJL 0zSBmIMJscnSG0rFXjA5I88ghZv7wmlf8rujXHUyjIY4ADvDKtL8BaRL98w6LQD6DtmB QPZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=lshyIJu954v2r/7XKXLH1/amde3r4n1sA3qGLei0xOw=; b=LBbLVHNavZqDjVE2MxgXaMDIqXwoczT0jHb/pV1A14GJqnsT28e/sVWAo/xJwy/znV 7xPdP8u3eOERckhj3Au9VrFo8XyLZV7ZgsvakenWcC5hZ38HDxVLhZUKfM+FaRmytJYC l5KhhDm6mSqy7AAZQnfILRzXqF4GecSkiaziLGxbhkyyegWOz4qMkX0Lfc0tCIfzr0GC wIC6i7G9VszUpjOPO7P6NPTxXKd8ZOzBHPQqjwTeL3pPnYbSSMY9Gw0gwvSYKnZMhN/R o2/4n8R9wxZDid1i2bd9oNTx+GoaJqv/AkdkrJbYceEZavGAk+stkRgwq0lYfM6Pr19J bL0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RbOV08DQ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si3477564pfh.38.2019.07.10.16.55.59; Wed, 10 Jul 2019 16:56:14 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RbOV08DQ; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727860AbfGJXwD (ORCPT + 99 others); Wed, 10 Jul 2019 19:52:03 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:39916 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfGJXwD (ORCPT ); Wed, 10 Jul 2019 19:52:03 -0400 Received: by mail-qt1-f195.google.com with SMTP id l9so4450673qtu.6; Wed, 10 Jul 2019 16:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lshyIJu954v2r/7XKXLH1/amde3r4n1sA3qGLei0xOw=; b=RbOV08DQF30yaBGCedUyuFI4e87n2/cGIvwajOkKhV6VPJaZJKAK1fsyEDE7Ig7vgh eWrQJN0kGIozDdlvYa0O/839xFHhIu6yLXuTp6mGBaMLTuCjMLwrzAv4Dv8p6ABLO7mM qQHJi6Il7/B7gPjzpxD/sCRYT4F0y/TY8PP3XZU+OrdI/30rWBH7ouhdJsr1zcxrFLxj FGKWp3x5LKW6/z1OUqiVc9OTXPsBnp2mIP+ff651wjdrM0YpqR5BSx91fXe81DukuaTj l+DtEABNrftVsinFEL/u5JUdg4b10bFf761mBhARk1WgVTfDk3DOB78ek6RYY3BdJFN7 FbLw== 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; bh=lshyIJu954v2r/7XKXLH1/amde3r4n1sA3qGLei0xOw=; b=FdTnO2NlQIkqkZkpvxYYRi6XkyBjzjffUQqbkBeBV7pxiLhpB1c/24Gprh5npbpFOT gPf/7sDXkgdXbSWtiQqOhvR3HvdGZbeNXTRjgTvSQ86VLPfIZt649ZFpfkg/XcYiS7vB yE0AGiDNVZUyn7ZwyUlhvOYwOB3X/g0r+xyLgbDOSQd+HBbbBUrxjzXqf0n/FaZ4YHP3 H9uJ8RokwV3llmTuobx2S21M04yVrWIC/6dsrHlXd0E5QcfbCie3viIdNNiJeR/5Zj2x gl6c0g85VjGnrRbGhabLEcX1i85prL79XVYzfK4GivSqzfgdkBzAzeKZW6IjrrCu8/6Y WukA== X-Gm-Message-State: APjAAAVXwUvI1hWmY3RPyLUA41nDLtRUMkZHBDyjoHKo88oPos0Tz8pT CSmcmhwke+HbBbvOrcycBJu4PujsjWHyQDEfZ6Q= X-Received: by 2002:ac8:2d56:: with SMTP id o22mr561834qta.171.1562802721973; Wed, 10 Jul 2019 16:52:01 -0700 (PDT) MIME-Version: 1.0 References: <20190708163121.18477-1-krzesimir@kinvolk.io> <20190708163121.18477-3-krzesimir@kinvolk.io> In-Reply-To: <20190708163121.18477-3-krzesimir@kinvolk.io> From: Andrii Nakryiko Date: Wed, 10 Jul 2019 16:51:51 -0700 Message-ID: Subject: Re: [bpf-next v3 02/12] selftests/bpf: Avoid a clobbering of errno To: Krzesimir Nowak 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 8, 2019 at 3:42 PM Krzesimir Nowak wrote: > > 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 test_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/testing/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 unpriv, uint32_t expected_val, > __u8 tmp[TEST_DATA_LEN << 2]; > __u32 size_tmp = sizeof(tmp); > uint32_t retval; > + int saved_errno; > int err; > > if (unpriv) > set_admin(true); > err = 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 = errno; > + saved_errno = 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? > printf("Did not run the program (not supported) "); > return 0; > -- > 2.20.1 >