From patchwork Wed Apr 27 16:55:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 53276 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 886A1385781D for ; Wed, 27 Apr 2022 16:55:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 886A1385781D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651078538; bh=+Gd6iVcFZeJYWHJRso11ZGf5YFLF2+Qwmdw66ee+A2I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UYm3tdecYlzc4OtJiJGaCZN+6ACbi1W5W3/5vv00jkGkiqlqrfYcwR+xgqOXYXBkn Tp4IdTMi1rdhWMQyES744XdM26PBWNnbXapz1g8drLIEMf0gW6Nf+3tChMgotFxs09 ZQcXLrXGENXfBniLwNniADmL+TKmXZjouFQmOQ0s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by sourceware.org (Postfix) with ESMTPS id BA22E385842B for ; Wed, 27 Apr 2022 16:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BA22E385842B Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-e656032735so2631728fac.0 for ; Wed, 27 Apr 2022 09:55:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=+Gd6iVcFZeJYWHJRso11ZGf5YFLF2+Qwmdw66ee+A2I=; b=ybmW6OGmFmHTCAQMcDTAhveDj09Z4T9+L0dIba/Cn/HlUhV8sAmrQjBP3L9dtbx7FJ KrEtCLcNVeg67Q0ReXC6C1MGui7gIdCMBjFh69HTjZxvRKYk6xN2B1ai7oSVsJC7Xcik CXT0xuZ/3DKqZAv/yvZ8I7xsGQcG/XPFwRO6loGRlJU4dX17vQ5ud+dtboWR5RYHoN3M a5b1xnklwuuqYaifz6zNDFOaqZW0J5Ir4Te0oO3ZuimyyDSlf8H/Xyo9NpijeuT8WXvc hoWugCEc38poSlrlLmeCuMD267hr5vrgrGKRTWpu4WYd7KLjK7MW3OBcjXPYg6QTNmXo YqtQ== X-Gm-Message-State: AOAM532cIrkQxCYAaxfm2P+HTQYmpxCOIevk5xs6HwVphn62HOf7ZWNm UllGM6bJT+WenthFlV5ZsPnNfvBjmvaD2A== X-Google-Smtp-Source: ABdhPJysXVH+6J+AIle9B5GEEYu3SjThaS4xKcpPhyJ0eApbjYKBjeW2T5Lieqli3FU9MROyeER32g== X-Received: by 2002:a05:6870:c390:b0:e2:602f:d81 with SMTP id g16-20020a056870c39000b000e2602f0d81mr11717939oao.262.1651078514535; Wed, 27 Apr 2022 09:55:14 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:4214:b613:182d:cdde:5f86]) by smtp.gmail.com with ESMTPSA id 74-20020a9d0850000000b00605d8ac3ce3sm1184331oty.1.2022.04.27.09.55.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:55:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] linux: Fix fchmodat with AT_SYMLINK_NOFOLLOW for 64 bit time_t (BZ#29097) Date: Wed, 27 Apr 2022 13:55:09 -0300 Message-Id: <20220427165509.2614678-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The AT_SYMLINK_NOFOLLOW emulation ues the default 32 bit stat internal calls, which fails with EOVERFLOW if the file constains timestamps beyond 2038. Checked on i686-linux-gnu. --- io/Makefile | 8 +++++--- io/tst-lchmod.c | 22 +++++++++++++++++++++- sysdeps/unix/sysv/linux/fchmodat.c | 4 ++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/io/Makefile b/io/Makefile index cf265dc9b9..b1710407d0 100644 --- a/io/Makefile +++ b/io/Makefile @@ -83,16 +83,17 @@ tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \ tst-ftw-bz28126 tests-time64 := \ + tst-fcntl-time64 \ + tst-fts-time64 \ tst-futimens-time64 \ tst-futimes-time64\ - tst-fts-time64 \ + tst-futimesat-time64 \ + tst-lchmod-time64 \ tst-lutimes-time64 \ tst-stat-time64 \ - tst-futimesat-time64 \ tst-utime-time64 \ tst-utimensat-time64 \ tst-utimes-time64 \ - tst-fcntl-time64 \ # tests-time64 # Likewise for statx, but we do not need static linking here. @@ -136,6 +137,7 @@ CFLAGS-close.c += -fexceptions -fasynchronous-unwind-tables CFLAGS-test-stat.c += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE CFLAGS-test-lfs.c += -D_LARGEFILE64_SOURCE +CFLAGS-tst-lchmod.c += -D_FILE_OFFSET_BITS=64 test-stat2-ARGS = Makefile . $(objpfx)test-stat2 diff --git a/io/tst-lchmod.c b/io/tst-lchmod.c index c644f565f6..c716edb9a9 100644 --- a/io/tst-lchmod.c +++ b/io/tst-lchmod.c @@ -66,10 +66,27 @@ select_path (bool do_relative_path, const char *full_path, const char *relative_ return full_path; } +static void +update_file_time_to_y2038 (const char *fname, int flags) +{ +#ifdef CHECK_TIME64 + /* Y2038 threshold plus 1 and 2 seconds. */ + const struct timespec ts[] = { { 0x80000001LL, 0}, { 0x80000002LL } }; + TEST_VERIFY_EXIT (utimensat (AT_FDCWD, fname, ts, flags) == 0); +#endif +} + static void test_1 (bool do_relative_path, int (*chmod_func) (int fd, const char *, mode_t, int)) { char *tempdir = support_create_temp_directory ("tst-lchmod-"); +#ifdef CHECK_TIME64 + if (!support_path_support_time64 (tempdir)) + { + puts ("info: test skipped, filesystem does not support 64 bit time_t"); + return; + } +#endif char *path_dangling = xasprintf ("%s/dangling", tempdir); char *path_file = xasprintf ("%s/file", tempdir); @@ -93,9 +110,12 @@ test_1 (bool do_relative_path, int (*chmod_func) (int fd, const char *, mode_t, xsymlink ("loop", path_loop); xsymlink ("target-does-not-exist", path_dangling); + update_file_time_to_y2038 (path_file, 0); + update_file_time_to_y2038 (path_to_file, AT_SYMLINK_NOFOLLOW); + /* Check that the modes do not collide with what we will use in the test. */ - struct stat64 st; + struct stat st; xstat (path_file, &st); TEST_VERIFY ((st.st_mode & 0777) != 1); xlstat (path_to_file, &st); diff --git a/sysdeps/unix/sysv/linux/fchmodat.c b/sysdeps/unix/sysv/linux/fchmodat.c index 7aa073bf3c..7aae02148a 100644 --- a/sysdeps/unix/sysv/linux/fchmodat.c +++ b/sysdeps/unix/sysv/linux/fchmodat.c @@ -48,8 +48,8 @@ fchmodat (int fd, const char *file, mode_t mode, int flag) /* Use fstatat because fstat does not work on O_PATH descriptors before Linux 3.6. */ - struct stat64 st; - if (__fstatat64 (pathfd, "", &st, AT_EMPTY_PATH) != 0) + struct __stat64_t64 st; + if (__fstatat64_time64 (pathfd, "", &st, AT_EMPTY_PATH) != 0) { __close_nocancel (pathfd); return -1;