From patchwork Tue Mar 14 20:26:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 19583 Received: (qmail 21833 invoked by alias); 14 Mar 2017 20:26:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21816 invoked by uid 89); 14 Mar 2017 20:26:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=909 X-HELO: mail-qt0-f178.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=Hc6cx3dJHKv/38jaXvKMphYkRE/TgdxU5bB172yLBOQ=; b=HwkzcOI9vdU8qPE5fH6GoSKCTlWHFabTNFv4I30UEX1TQiry7q2PWGpV+vuATpWCyK MF8UyAlkoE4AXQOjXq1zgeTjEWJFIE48ym6nV/YUucx+KSItvNI7U2+clDZuOLhfY+iv HVCsx6vV/uCtGD3uJpv3rZTjRcoS2QsOBS7n/Oibo5eiM94td9JVGtfTCIML0zvnQfqO 3RRDbakLuK1qXMqKG4WEDUF5rSzUqotbp79ScJGXs/06k5anHK5sXfh0iOfoqDEJU3e9 xN6BX24j4IMxyVAUzi+I/CbjwmmFqOlMud9HEKvL3ddwVf+NIApkZBb3gVNSam+HpNbU JSZA== X-Gm-Message-State: AMke39mVfjuasmYDsx8vn/UG4B+ru5zHDf+xIQb479i8zA5MC3o2W/0FIph8HfZUf7+I4e+W X-Received: by 10.200.35.250 with SMTP id r55mr39588997qtr.280.1489523163311; Tue, 14 Mar 2017 13:26:03 -0700 (PDT) Subject: Re: [PATCH v2] Fix test-errno issues To: libc-alpha@sourceware.org References: <1489523045-21530-1-git-send-email-adhemerval.zanella@linaro.org> From: Adhemerval Zanella Message-ID: <505e6f6a-e22a-bdc3-062d-92e2a99744a6@linaro.org> Date: Tue, 14 Mar 2017 17:26:01 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: <1489523045-21530-1-git-send-email-adhemerval.zanella@linaro.org> And I did not used the -C -M option on this one... the following one is essentially the same patch formatted with -C -M: On 14/03/2017 17:24, Adhemerval Zanella wrote: > Changes from previous version: > > - Change open tests from EINVAL to EISDIR. > > -- > > This patch fixes multiple issues of test-errno.c (9a56f8718341): > > - Rename Linux test-errno.c to test-errno-linux.c to avoid build > the same source for both tests. > > - Add a mlock check for 32 bits build running on 64 bits kernels. > Althuough man pages states that mlock fails with EINVAL if final > address overflows, kernels does not return it for aforementioned > condition (it returns ENOMEM instead). Although it seems to be > a kernel issue for compat syscall handling, I think it is worth > to still check syscall return and document the behavior. > > - Initialize option length for setsockopt check. > > Checked on x86_64-linux-gnu and i686-linux-gnu (running on 64 bits > kernel). > > * posix/test-errno.c (do_test): Initialize setsockopt optlen. > * sysdeps/unix/sysv/linux/test-errno.c: Move to ... > * sysdeps/unix/sysv/linux/test-errno-linux.c: ... here. > (do_test): Handle mlock return on 64 bits kernels with 32 bits > binaries and change open test. diff --git a/posix/test-errno.c b/posix/test-errno.c index 98df344..c2bfd8a 100644 --- a/posix/test-errno.c +++ b/posix/test-errno.c @@ -131,7 +131,7 @@ do_test (void) fails |= test_wrp (EINVAL, mprotect, (void *) -1, pagesize, -1); fails |= test_wrp (EINVAL, msync, (void *) -1, pagesize, -1); fails |= test_wrp (EINVAL, munmap, (void *) -1, 0); - fails |= test_wrp (EINVAL, open, "/bin/sh", -1, 0); + fails |= test_wrp (EISDIR, open, "/bin", EISDIR, O_WRONLY); fails |= test_wrp (EBADF, read, -1, buf, 1); fails |= test_wrp (EINVAL, readlink, "/", buf, -1); fails |= test_wrp (EBADF, readv, -1, iov, 1); @@ -142,7 +142,7 @@ do_test (void) fails |= test_wrp (EBADF, send, -1, buf, 1, 0); fails |= test_wrp (EBADF, sendmsg, -1, &msg, 0); fails |= test_wrp (EBADF, sendto, -1, buf, 1, 0, &sa, sl); - fails |= test_wrp (EBADF, setsockopt, -1, 0, 0, buf, sl); + fails |= test_wrp (EBADF, setsockopt, -1, 0, 0, buf, sizeof (*buf)); fails |= test_wrp (EBADF, shutdown, -1, SHUT_RD); fails |= test_wrp (EBADF, write, -1, "Hello", sizeof ("Hello") ); fails |= test_wrp (EBADF, writev, -1, iov, 1 ); diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 6b7aa3f..1872cdb 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -43,7 +43,7 @@ sysdep_headers += sys/mount.h sys/acct.h sys/sysctl.h \ bits/mman-linux.h tests += tst-clone tst-clone2 tst-fanotify tst-personality tst-quota \ - tst-sync_file_range test-errno + tst-sync_file_range test-errno-linux # Generate the list of SYS_* macros for the system calls (__NR_* macros). diff --git a/sysdeps/unix/sysv/linux/test-errno.c b/sysdeps/unix/sysv/linux/test-errno-linux.c similarity index 77% rename from sysdeps/unix/sysv/linux/test-errno.c rename to sysdeps/unix/sysv/linux/test-errno-linux.c index ab3735f..b00d14e 100644 --- a/sysdeps/unix/sysv/linux/test-errno.c +++ b/sysdeps/unix/sysv/linux/test-errno-linux.c @@ -1,4 +1,5 @@ /* Test that failing system calls do set errno to the correct value. + Linux sycalls version. Copyright (C) 2017 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -90,9 +91,37 @@ fail; \ })) +#define test_wrp_rv2(rtype, prtype, experr1, experr2, syscall, ...) \ + (__extension__ ({ \ + errno = 0xdead; \ + rtype ret = syscall (__VA_ARGS__); \ + int err = errno; \ + int fail; \ + if (ret == (rtype) -1 && (err == experr1 || err == experr2)) \ + fail = 0; \ + else \ + { \ + fail = 1; \ + if (ret != (rtype) -1) \ + printf ("FAIL: " #syscall ": didn't fail as expected" \ + " (return "prtype")\n", ret); \ + else if (err == 0xdead) \ + puts("FAIL: " #syscall ": didn't update errno\n"); \ + else if (err != experr1 && err != experr2) \ + printf ("FAIL: " #syscall \ + ": errno is: %d (%s) expected: %d (%s) or %d (%s)\n", \ + err, strerror (err), experr1, strerror (experr1), \ + experr2, strerror (experr2)); \ + } \ + fail; \ + })) + #define test_wrp(experr, syscall, ...) \ test_wrp_rv(int, "%d", experr, syscall, __VA_ARGS__) +#define test_wrp2(experr1, experr2, syscall, ...) \ + test_wrp_rv2(int, "%d", experr1, experr2, syscall, __VA_ARGS__) + static int do_test (void) { @@ -120,7 +149,12 @@ do_test (void) fails |= test_wrp (ESRCH, getpgid, -1); fails |= test_wrp (EINVAL, inotify_add_watch, -1, "/", 0); fails |= test_wrp (EINVAL, mincore, (void *) -1, 0, vec); - fails |= test_wrp (EINVAL, mlock, (void *) -1, 1); // different errors + /* mlock fails if the result of the addition addr+len was less than addr + (which indicates final address overflow), however on 32 bits binaries + running on 64 bits kernels, internal syscall address check won't result + in an invalid address and thus syscalls fails later in vma + allocation. */ + fails |= test_wrp2 (EINVAL, ENOMEM, mlock, (void *) -1, 1); fails |= test_wrp (EINVAL, nanosleep, &ts, &ts); fails |= test_wrp (EINVAL, poll, &pollfd, -1, 0); fails |= test_wrp (ENODEV, quotactl, Q_GETINFO, NULL, -1, (caddr_t) &dqblk);