DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 49EDathC3413838 Authentication-Results: delorie.com; dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=rmVoC9ep X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79F40385AE5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1728913013; bh=uN9dGP2yRXyB6m+L27xf+x2sHP+SBZhPEx7PpcUXYdA=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=rmVoC9epp36V1kjDUyv6fodTI1tQF2/MeXqiBCpTqrbqZ1Bd9ztBgMf/N6bOJ9+OT YdnjqvaVFC1mY5zTRkDQkml+RZO6HvdRvkpWvP6IJSJ8BrEYFQEPt5Xir/Bm16WWlL 8uEbMG2pckYsOzjGwc0R2VANLnh6q/bRYs0skjLA= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 578D4385AC2E ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 578D4385AC2E ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728912977; cv=none; b=j+49HtdD9NA1snpZeztjMhjsu0cxA2JfmHU/D2rpfkNn7D5xJ30RSYY0YwXIqGAICLAuZN6Z8MV2EQZqSxrYVZtxwnHXiTwlTnEVFHqfGvnCCQdnZhHJ5MpRt4A+PhfCwuTMOMnQN1rIuyqOXKKCa56j9vrEV/7v/PLC5EvMd7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728912977; c=relaxed/simple; bh=67V8Gqx23O5/lbsCL5fdM0MOFssBT43DabFz62EJL2Y=; h=From:Subject:To:Message-ID:Date:MIME-Version; b=qBLu8JwLP/PNMCfK2kC2n55rAwWpRhhXhGBFExsHUZRTUve4pq78c1SZSTIMEkxXbznyfTEmYvP3T3FiD6tzZKuwZ6V2J9lN9sBBMrBW1KlMxA6J2SZ/BLitQ/tdg0ph6bUN7KhA/9laq+h6eDTea80iKrCnbv/SCSTwoODu/uk= ARC-Authentication-Results: i=1; server2.sourceware.org Subject: cygwin 3.5.4-1: lockf() aborts on overlap and does not fail on overflow To: cygwin AT cygwin DOT com Message-ID: Date: Mon, 14 Oct 2024 15:36:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 SeaMonkey/2.53.18.2 MIME-Version: 1.0 X-TOI-EXPURGATEID: 150726::1728912962-DAFFB5D9-D1BFE51E/0/0 CLEAN NORMAL X-TOI-MSGID: b06d39dc-1bbe-4b2f-8bc5-68a8fb18a248 X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, BODY_8BITS, FREEMAIL_FROM, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Christian Franke via Cygwin Reply-To: cygwin AT cygwin DOT com Cc: Christian Franke Content-Type: text/plain; charset="utf-8"; Format="flowed" Sender: "Cygwin" Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 49EDathC3413838 Two possibly independent bugs found by 'stress-ng --lockf ...': 1) lockf() may abort the process with api_fatal() if the new range partly overlaps with two ranges previously locked by the same process. 2) lockf() prints a warning on too many locks and returns success. It should not print a warning and fail with ENOLCK instead. Testcase for both: $ uname -r 3.5.4-1.x86_64 $ cat locktest.c #include #include #include static int lock_at(int fd, int off, int size) {   if (lseek(fd, off, SEEK_SET) < 0) {     perror("lseek"); return -1;   }   printf("\rlock %d-%d\n", off, off + size - 1); fflush(stdout);   if (lockf(fd, F_LOCK, size) < 0) {     perror("lock"); return -1;   }   return 0; } int main(int argc, char **argv) {   int fd = open("locktest.tmp", O_RDWR|O_CREAT, 0666);   if (fd < 0) {     perror("open"); return 1;   }   if (argc == 1) {     lock_at(fd, 0, 2);     lock_at(fd, 2, 2);     lock_at(fd, 1, 2);   }   else {     for (int i = 0; i < 914; i++)       if (lock_at(fd, i, 1))         return 1;   }   printf("\rdone\n");   return 0; } $ gcc -o locktest locktest.c $ ./locktest lock 0-1 lock 2-3 lock 1-2      1 [main] locktest 44864 C:\cygwin64\tmp\locktest.exe: \        *** fatal error - NtCreateEvent(lock): 0xC0000035\        Hangup $ ./locktest loop lock 0-0 lock 1-1 lock 2-2 lock 3-3 ... lock 909-909 lock 910-910 lock 911-911       0 [main] locktest 44865 inode_t::get_all_locks_list: \         Warning, can't handle more than 910 locks per file. lock 912-912     727 [main] locktest 44865 inode_t::get_all_locks_list: \         Warning, can't handle more than 910 locks per file. lock 913-913    1329 [main] locktest 44865 inode_t::get_all_locks_list: \         Warning, can't handle more than 910 locks per file. done There is possibly also an off-by-one error as the 912'th lockf() prints the first warning. -- Regards, Christian -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple