From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51031 invoked by alias); 28 Sep 2018 19:22:04 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 51016 invoked by uid 89); 28 Sep 2018 19:22:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.1 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=__offset, 7549 X-Spam-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mail-qt1-f193.google.com Received: from mail-qt1-f193.google.com (HELO mail-qt1-f193.google.com) (209.85.160.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 28 Sep 2018 19:22:01 +0000 Received: by mail-qt1-f193.google.com with SMTP id h22-v6so7814389qtr.13 for ; Fri, 28 Sep 2018 12:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=3AIBXzsk8qM1MzdeEaR83fh8JCXeJJ85AO3Zij+gbC4=; b=JzDNRGsrCkye7d1JO9Wl+LPs9dp7CtGDHVuQ5epAG04fttAJnzRAuI2YHXzn9tyYlV YzYgs6VBQ2in+45A0BsnEi9FMeo433v7isEpY77I0hi24LYf+cUTAiqwnlSl7t4A6901 9EAl4kSMaYyxQ3BtRqQeVW12KGiTfRhMERmus= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3AIBXzsk8qM1MzdeEaR83fh8JCXeJJ85AO3Zij+gbC4=; b=aJxGCnEiJk3viHjckJ8JuXhrGHRUcTpzTNrn9Pyta919RGrQodoHTV79ViscGZ8vT3 aPoPDoIEaZOnaS4Qs9NBMzUYN62ZU6GsH+qKRIdonXbp8bKhLYboc/WOFWZvqXd4shjg iVDja9mA/wDOeSHeG6nOIzCtj7V2diy4+iIu3Qmaq9RM75VPcP3XIlx4RojdoDFm+xM3 0JaokTVxbjbbyufYBlU2xvFDHAliKyZB8ZVl+bSjwv/9q9jHSwQbY3p8RtV4cH0oJlLq 4+ZAIKd7y9fL5QbbaXFqrl/kW8zMP1i/wQumkIa003spFGnRMzomqm242GLtQ2oIz7Lx aNUg== X-Gm-Message-State: ABuFfojWIpgVsXMXZtVN3rmsAUA4t9TeC4/65BNwo7bdE55CKmerRG9Q SDWUpMVqCaYXxiTXvNXBO8EwD+GGGKw= X-Google-Smtp-Source: ACcGV63vecpQglTF1QmNXkgq+m3/2Oo7hrqvRhDuwfvXR4r03gCn9Pp75UHLhsfmmL6sU1100Py83w== X-Received: by 2002:a0c:ad37:: with SMTP id u52-v6mr48592qvc.132.1538162519221; Fri, 28 Sep 2018 12:21:59 -0700 (PDT) Received: from localhost.localdomain ([201.82.189.205]) by smtp.googlemail.com with ESMTPSA id k185-v6sm3182431qkd.27.2018.09.28.12.21.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 12:21:58 -0700 (PDT) From: Adhemerval Zanella To: libc-stable@sourceware.org Cc: Florian Weimer Subject: [2.26 COMMITTED 1/2] preadv2/pwritev2: Handle offset == -1 [BZ #22753] Date: Mon, 01 Jan 2018 00:00:00 -0000 Message-Id: <20180928192152.15005-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.17.1 X-IsSubscribed: yes X-SW-Source: 2018-09/txt/msg00009.txt.bz2 From: Florian Weimer Reviewed-by: Adhemerval Zanella (cherry picked from commit d4b4a00a462348750bb18544eb30853ee6ac5d10) --- ChangeLog | 17 ++++++++++++ NEWS | 1 + manual/llio.texi | 21 ++++++++++----- misc/tst-preadvwritev-common.c | 38 +++++++++++++++++++++++++++ misc/tst-preadvwritev2.c | 1 + misc/tst-preadvwritev64v2.c | 1 + sysdeps/posix/preadv2.c | 5 +++- sysdeps/posix/preadv64v2.c | 5 +++- sysdeps/posix/pwritev2.c | 5 +++- sysdeps/posix/pwritev64v2.c | 5 +++- sysdeps/unix/sysv/linux/preadv2.c | 5 +++- sysdeps/unix/sysv/linux/preadv64v2.c | 6 ++++- sysdeps/unix/sysv/linux/pwritev2.c | 5 +++- sysdeps/unix/sysv/linux/pwritev64v2.c | 5 +++- 14 files changed, 105 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index a868a652f7..d5e3403e8b 100644 --- a/NEWS +++ b/NEWS @@ -135,6 +135,7 @@ The following bugs are resolved with this release: (CVE-2018-1000001) [22685] powerpc: Fix syscalls during early process initialization [22715] x86-64: Properly align La_x86_64_retval to VEC_SIZE + [22753] libc: preadv2/pwritev2 fallback code should handle offset=-1 [22774] malloc: Integer overflow in malloc (CVE-2018-6551) [22786] Fix path length overflow in realpath [23005] resolv: Fix crash in resolver on memory allocation failure diff --git a/manual/llio.texi b/manual/llio.texi index e72c53c785..4ce9ee360e 100644 --- a/manual/llio.texi +++ b/manual/llio.texi @@ -754,9 +754,13 @@ When the source file is compiled using @code{_FILE_OFFSET_BITS == 64} on a @c This is a syscall for Linux v4.6. The sysdeps/posix fallback emulation @c is also MT-Safe since it calls preadv. -This function is similar to the @code{preadv} function, with the difference -it adds an extra @var{flags} parameter of type @code{int}. The supported -@var{flags} are dependent of the underlying system. For Linux it supports: +This function is similar to the @code{preadv} function, with the +difference it adds an extra @var{flags} parameter of type @code{int}. +Additionally, if @var{offset} is @math{-1}, the current file position +is used and updated (like the @code{readv} function). + +The supported @var{flags} are dependent of the underlying system. For +Linux it supports: @vtable @code @item RWF_HIPRI @@ -823,10 +827,13 @@ When the source file is compiled using @code{_FILE_OFFSET_BITS == 64} on a @c This is a syscall for Linux v4.6. The sysdeps/posix fallback emulation @c is also MT-Safe since it calls pwritev. -This function is similar to the @code{pwritev} function, with the difference -it adds an extra @var{flags} parameter of type @code{int}. The supported -@var{flags} are dependent of the underlying system and for Linux it supports -the same ones as for @code{preadv2}. +This function is similar to the @code{pwritev} function, with the +difference it adds an extra @var{flags} parameter of type @code{int}. +Additionally, if @var{offset} is @math{-1}, the current file position +should is used and updated (like the @code{writev} function). + +The supported @var{flags} are dependent of the underlying system. For +Linux, the supported flags are the same as those for @code{preadv2}. When the source file is compiled with @code{_FILE_OFFSET_BITS == 64} the @code{pwritev2} function is in fact @code{pwritev64v2} and the type diff --git a/misc/tst-preadvwritev-common.c b/misc/tst-preadvwritev-common.c index 676d4953ac..7f9a63f1f5 100644 --- a/misc/tst-preadvwritev-common.c +++ b/misc/tst-preadvwritev-common.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -25,6 +26,7 @@ #include #include +#include static char *temp_filename; static int temp_fd; @@ -50,6 +52,42 @@ do_prepare (int argc, char **argv) pwritev (__fd, __iov, __iovcnt, __offset) #endif +static __attribute__ ((unused)) void +do_test_without_offset (void) +{ + xftruncate (temp_fd, 0); + + xwrite (temp_fd, "123", 3); + xlseek (temp_fd, 2, SEEK_SET); + { + struct iovec iov[] = + { + { (void *) "abc", 3 }, + { (void *) "xyzt", 4 }, + }; + TEST_COMPARE (PWRITEV (temp_fd, iov, array_length (iov), -1), 7); + } + TEST_COMPARE (xlseek (temp_fd, 0, SEEK_CUR), 9); + + xlseek (temp_fd, 1, SEEK_SET); + char buf1[3]; + char buf2[2]; + { + struct iovec iov[] = + { + { buf1, sizeof (buf1) }, + { buf2, sizeof (buf2) }, + }; + TEST_COMPARE (PREADV (temp_fd, iov, array_length (iov), -1), + sizeof (buf1) + sizeof (buf2)); + TEST_COMPARE (memcmp ("2ab", buf1, sizeof (buf1)), 0); + TEST_COMPARE (memcmp ("cx", buf2, sizeof (buf2)), 0); + TEST_COMPARE (xlseek (temp_fd, 0, SEEK_CUR), 6); + } + + xftruncate (temp_fd, 0); +} + static int do_test_with_offset (off_t offset) { diff --git a/misc/tst-preadvwritev2.c b/misc/tst-preadvwritev2.c index 682c7579da..225f5e59c1 100644 --- a/misc/tst-preadvwritev2.c +++ b/misc/tst-preadvwritev2.c @@ -29,6 +29,7 @@ static int do_test (void) { do_test_with_invalid_flags (); + do_test_without_offset (); return do_test_with_offset (0); } diff --git a/misc/tst-preadvwritev64v2.c b/misc/tst-preadvwritev64v2.c index 9ddc7625f0..facdbdca61 100644 --- a/misc/tst-preadvwritev64v2.c +++ b/misc/tst-preadvwritev64v2.c @@ -31,6 +31,7 @@ static int do_test (void) { do_test_with_invalid_flags (); + do_test_without_offset (); return do_test_with_offset (0); } diff --git a/sysdeps/posix/preadv2.c b/sysdeps/posix/preadv2.c index d27f7028ed..fe73d3cbea 100644 --- a/sysdeps/posix/preadv2.c +++ b/sysdeps/posix/preadv2.c @@ -32,7 +32,10 @@ preadv2 (int fd, const struct iovec *vector, int count, OFF_T offset, return -1; } - return preadv (fd, vector, count, offset); + if (offset == -1) + return __readv (fd, vector, count); + else + return preadv (fd, vector, count, offset); } #endif diff --git a/sysdeps/posix/preadv64v2.c b/sysdeps/posix/preadv64v2.c index ce7cb40bf2..8569c8b398 100644 --- a/sysdeps/posix/preadv64v2.c +++ b/sysdeps/posix/preadv64v2.c @@ -29,7 +29,10 @@ preadv64v2 (int fd, const struct iovec *vector, int count, OFF_T offset, return -1; } - return preadv64 (fd, vector, count, offset); + if (offset == -1) + return __readv (fd, vector, count); + else + return preadv64 (fd, vector, count, offset); } #ifdef __OFF_T_MATCHES_OFF64_T diff --git a/sysdeps/posix/pwritev2.c b/sysdeps/posix/pwritev2.c index 7ec8cbc407..b24b491a81 100644 --- a/sysdeps/posix/pwritev2.c +++ b/sysdeps/posix/pwritev2.c @@ -32,7 +32,10 @@ pwritev2 (int fd, const struct iovec *vector, int count, OFF_T offset, return -1; } - return pwritev (fd, vector, count, offset); + if (offset == -1) + return __writev (fd, vector, count); + else + return pwritev (fd, vector, count, offset); } #endif diff --git a/sysdeps/posix/pwritev64v2.c b/sysdeps/posix/pwritev64v2.c index be98aeed9d..ae4c4284c2 100644 --- a/sysdeps/posix/pwritev64v2.c +++ b/sysdeps/posix/pwritev64v2.c @@ -30,7 +30,10 @@ pwritev64v2 (int fd, const struct iovec *vector, int count, OFF_T offset, return -1; } - return pwritev64 (fd, vector, count, offset); + if (offset == -1) + return __writev (fd, vector, count); + else + return pwritev64 (fd, vector, count, offset); } #ifdef __OFF_T_MATCHES_OFF64_T diff --git a/sysdeps/unix/sysv/linux/preadv2.c b/sysdeps/unix/sysv/linux/preadv2.c index 137e2dd791..a7a3aeeee6 100644 --- a/sysdeps/unix/sysv/linux/preadv2.c +++ b/sysdeps/unix/sysv/linux/preadv2.c @@ -49,7 +49,10 @@ preadv2 (int fd, const struct iovec *vector, int count, off_t offset, __set_errno (ENOTSUP); return -1; } - return preadv (fd, vector, count, offset); + if (offset == -1) + return __readv (fd, vector, count); + else + return preadv (fd, vector, count, offset); } #endif diff --git a/sysdeps/unix/sysv/linux/preadv64v2.c b/sysdeps/unix/sysv/linux/preadv64v2.c index 8f413253f4..53c946861c 100644 --- a/sysdeps/unix/sysv/linux/preadv64v2.c +++ b/sysdeps/unix/sysv/linux/preadv64v2.c @@ -47,7 +47,11 @@ preadv64v2 (int fd, const struct iovec *vector, int count, off64_t offset, __set_errno (ENOTSUP); return -1; } - return preadv64 (fd, vector, count, offset); + + if (offset == -1) + return __readv (fd, vector, count); + else + return preadv64 (fd, vector, count, offset); } #ifdef __OFF_T_MATCHES_OFF64_T diff --git a/sysdeps/unix/sysv/linux/pwritev2.c b/sysdeps/unix/sysv/linux/pwritev2.c index 8e5032fe2f..17677df98d 100644 --- a/sysdeps/unix/sysv/linux/pwritev2.c +++ b/sysdeps/unix/sysv/linux/pwritev2.c @@ -45,7 +45,10 @@ pwritev2 (int fd, const struct iovec *vector, int count, off_t offset, __set_errno (ENOTSUP); return -1; } - return pwritev (fd, vector, count, offset); + if (offset == -1) + return __writev (fd, vector, count); + else + return pwritev (fd, vector, count, offset); } #endif diff --git a/sysdeps/unix/sysv/linux/pwritev64v2.c b/sysdeps/unix/sysv/linux/pwritev64v2.c index d2800c6657..f5753eede5 100644 --- a/sysdeps/unix/sysv/linux/pwritev64v2.c +++ b/sysdeps/unix/sysv/linux/pwritev64v2.c @@ -47,7 +47,10 @@ pwritev64v2 (int fd, const struct iovec *vector, int count, off64_t offset, __set_errno (ENOTSUP); return -1; } - return pwritev64 (fd, vector, count, offset); + if (offset == -1) + return __writev (fd, vector, count); + else + return pwritev64 (fd, vector, count, offset); } #ifdef __OFF_T_MATCHES_OFF64_T -- 2.17.1