From patchwork Sun Jul 30 19:25:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1814684 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=uFMuEnfv; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RDWZd6mmQz1yVt for ; Mon, 31 Jul 2023 05:26:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C25363857705 for ; Sun, 30 Jul 2023 19:26:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C25363857705 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690745191; bh=TvW81hJq7ieVWIv1qV7qMjlCHF/zY46Fqn69vkhNDwQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uFMuEnfvDqcxs5/7wIK6dBLojRrxaTCSjHAKb+GRzLBiBjYv2CSctWq9p9V/oglnm GZiMnVVC4r9wLDGMd3+lYP5I/6pu0lXjHKfEDgRx6i+fgCKPywu+leoCVpcv126qwB 9ib2ueaXj+nMkbo/pYGoIdu1gfqUeoOdzD8QeNSA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id 7751E3858D38 for ; Sun, 30 Jul 2023 19:26:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7751E3858D38 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f95bf5c493so5986725e87.3 for ; Sun, 30 Jul 2023 12:26:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690745173; x=1691349973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TvW81hJq7ieVWIv1qV7qMjlCHF/zY46Fqn69vkhNDwQ=; b=OwDvWPcK1k5sNXIGZjvkTZnWvSYy0vNCsyhuSI+7rwFQ2lQItOYGju2GoZi6RWYO8+ jRDGprhuxXDS7fek4Ejq0nWkbV9pCNlyMbH2PbGjspA0unXHyUxuyGHnLZRz158aXsQh frpvg2YW6uLaNLLK9rbcAHfMr5arzFhAKTNc+MqmX4VYUWTbGTpBA9D59ICkbeHWJPqz 62eqn0WVYqEEBoc7V3cA7I7q2yE9jbErzALrJnJRP8NAtE9j9d4kkGxSQ5jw+z7p28Mn IzsMAI7M1IIu3cw3Es9rPqqsCoswvSzjocmSFtCIisze0Jfxj7jpF4nB+bOypRvU+/Ut ydcA== X-Gm-Message-State: ABy/qLZoY/ejWl6iAJhs/HOmTIhUxpffH7f6Htw1wOjH6cz9MrUujHnQ gRWeZuEVYGxlEjrPOLbZqUQm7ytgiMbANg== X-Google-Smtp-Source: APBJJlGVVbTSaD5+x4bunLiPqf1SZwztxTFWySdN41ohPMCnq3lBHAsC7gDQMxc9qXgMhKG+aIFoUw== X-Received: by 2002:a05:6512:2508:b0:4fe:1681:9378 with SMTP id be8-20020a056512250800b004fe16819378mr5219068lfb.66.1690745172840; Sun, 30 Jul 2023 12:26:12 -0700 (PDT) Received: from localhost.localdomain ([2a02:2168:b344:a600:4435:f106:1598:d2b0]) by smtp.gmail.com with ESMTPSA id y8-20020a197508000000b004fe2f085d5csm532447lfe.299.2023.07.30.12.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 12:26:12 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v4 1/6] Fix calling fcntl64 (fd, F_SETLK, &flock64) Date: Sun, 30 Jul 2023 22:25:56 +0300 Message-ID: <20230730192605.2423480-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230730192605.2423480-1-bugaevc@gmail.com> References: <20230730192605.2423480-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" F_GETLK, F_SETLK, F_SETLKW must always be used with the regular struct flock, not struct flock64, even if the function being called is fcntl64. There are separate commands, F_GETLK64, F_SETLK64, and F_SETLKW64, that are used with struct flock64. This is in contrast with the OFD locking commands (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW) that must be used with struct flock in fcntl calls, and with struct flock64 in fcntl64 calls. These mistakes were spotted by enabling the fcntl fortification that is added in a following commit. Fixes: 61d3db428176d9d0822e4e680305fe34285edff2 "login: pututxline could fail to overwrite existing entries [BZ #24902]" Fixes: f6233ab412c3bebebacf65745e775e01506dd58d "Linux: Add io/tst-o_path-locks test" Signed-off-by: Sergey Bugaev Reviewed-by: Adhemerval Zanella --- Please tell me if I'm misunderstanding this! login/tst-pututxline-lockfail.c | 2 +- sysdeps/unix/sysv/linux/tst-o_path-locks.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/login/tst-pututxline-lockfail.c b/login/tst-pututxline-lockfail.c index 214d1106..ca82ba42 100644 --- a/login/tst-pututxline-lockfail.c +++ b/login/tst-pututxline-lockfail.c @@ -77,7 +77,7 @@ subprocess_lock_file (void) .l_type = F_RDLCK, fl.l_whence = SEEK_SET, }; - TEST_COMPARE (fcntl64 (fd, F_SETLKW, &fl), 0); + TEST_COMPARE (fcntl64 (fd, F_SETLKW64, &fl), 0); /* Signal to the main process that the lock has been acquired. */ xpthread_barrier_wait (barrier); diff --git a/sysdeps/unix/sysv/linux/tst-o_path-locks.c b/sysdeps/unix/sysv/linux/tst-o_path-locks.c index 0036868d..c3d1c0dc 100644 --- a/sysdeps/unix/sysv/linux/tst-o_path-locks.c +++ b/sysdeps/unix/sysv/linux/tst-o_path-locks.c @@ -39,7 +39,7 @@ subprocess (void *closure) { int fd = xopen (path, O_RDWR, 0); struct flock64 lock = { .l_type = F_WRLCK, }; - int ret = fcntl64 (fd, F_SETLK, &lock); + int ret = fcntl64 (fd, F_SETLK64, &lock); if (ret == 0) *shared_errno = 0; else @@ -76,7 +76,7 @@ do_test (void) TEST_VERIFY (!probe_lock ()); struct flock64 lock = { .l_type = F_WRLCK, }; - TEST_COMPARE (fcntl64 (fd, F_SETLK, &lock), 0); + TEST_COMPARE (fcntl64 (fd, F_SETLK64, &lock), 0); /* The lock has been acquired. */ TEST_VERIFY (probe_lock ()); @@ -87,7 +87,7 @@ do_test (void) TEST_VERIFY (!probe_lock ()); /* But not if it is an O_PATH descriptor. */ - TEST_COMPARE (fcntl64 (fd, F_SETLK, &lock), 0); + TEST_COMPARE (fcntl64 (fd, F_SETLK64, &lock), 0); xclose (xopen (path, O_PATH, 0)); TEST_VERIFY (probe_lock ());