From patchwork Tue Aug 9 05:11:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12939349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 697C1C25B0C for ; Tue, 9 Aug 2022 05:11:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbiHIFLq (ORCPT ); Tue, 9 Aug 2022 01:11:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbiHIFLo (ORCPT ); Tue, 9 Aug 2022 01:11:44 -0400 Received: from mail-vs1-xe34.google.com (mail-vs1-xe34.google.com [IPv6:2607:f8b0:4864:20::e34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 409351EED6 for ; Mon, 8 Aug 2022 22:11:43 -0700 (PDT) Received: by mail-vs1-xe34.google.com with SMTP id v128so10835771vsb.10 for ; Mon, 08 Aug 2022 22:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=miTEw8LC5NaQAm+ykLphAFNNkaAcmCcx5VsX9OURAFc=; b=F0xVlEOqvhK/7JBGn870hZv7HO0ar8KvebO5E/lM+VD1XeGSsY9JXzEsdJ4It/TxS2 ctbikDuqzluotMwGOvmxUFbayTCuhDEyyiqfoUvYuUO3RGiriK1laTvN30LOBxf6oNfU lOwxSE6jPRf7075FUPd4C+y1ZPLFFTKtIFpxpcmlWEeNt+SIkiHV0ZOFzNHGGII509VF 4EErp9oHf9e9zZra7TuI4lgOCcyuM5TT9vg6zpjLbAPJ6538iPXJ++fFtNPz/bSZ5lmO s2jAtS7fvo0M8qh3E4K8ypbJBAmNlxfaGjk1ENfMtcfWs4MnfTCcvF+9s35s4/RP3JF3 BMCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=miTEw8LC5NaQAm+ykLphAFNNkaAcmCcx5VsX9OURAFc=; b=ecYWaOAdOtN2k9EAf24v+qtY2QMWbFSWLnOnEgoJetkD5Z/wQL3jKnzZ8Ln93SKcJp 8yQoPbEoPXhgA/BrF/kf/JkE16z1ZDUfRXacetMiSaGKht+XZwkfaZ3C5P9guXEDhhSo 2v2JTxIp3/SOeYZ4s9b/oge7GJNo1vaHyRkKZ/cOu6Fcw1ETUBEKJuUIFlznFP94sUZO SHUcgY7VKbhJt4Q+6n2rkvaz+ZXMtVJKWFjD4342w36k/bEl/7KK0q+KtRxWuGElfcp9 abAjP3Kn9kAhryLud4A/6Y9G/yW/aBKwYiO/4koMdMWrCMEqSoVrlZVjDIoY/be/47l/ CsKg== X-Gm-Message-State: ACgBeo0WzOYyZkMtCbV5nK6sqqhuxU8JJhPX7W5t9fUzTOxemH36/JFI QGUR4MCX3ukwfQ2/XwXsXmbEJCK0hef+d5Rdsyo+kWyPBEs= X-Google-Smtp-Source: AA6agR4zXiSpiQdzHLjx5EC/LPpdj98PrMvVxefjxTX7cTSj3yWbeAtrV+X0kpmPI1kvS9FxdAxhuZ5kJKWnbbUKlww= X-Received: by 2002:a67:b24b:0:b0:357:31a6:1767 with SMTP id s11-20020a67b24b000000b0035731a61767mr8651957vsh.29.1660021901836; Mon, 08 Aug 2022 22:11:41 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Tue, 9 Aug 2022 00:11:31 -0500 Message-ID: Subject: [PATCH] fcntl F_GETLK return F_ULOCK if the whole file is locked by F_WRLCK To: CIFS Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Any comments on Paulo's patch? It fixes a regression in connectathon test 2 I tentatively merged it into cifs-2.6.git for-next and added Cc:Stable From 97bba24c9f80a7181bfc58bbf819209fb8b21128 Mon Sep 17 00:00:00 2001 From: Paulo Alcantara Date: Mon, 8 Aug 2022 13:41:18 -0300 Subject: [PATCH] cifs: fix lock length calculation The lock length was wrongly set to 0 when fl_end == OFFSET_MAX, thus failing to lock the whole file when l_start=0 and l_len=0. This fixes test 2 from cthon04. Before patch: $ ./cthon04/lock/tlocklfs -t 2 /mnt Creating parent/child synchronization pipes. Test #1 - Test regions of an unlocked file. Parent: 1.1 - F_TEST [ 0, 1] PASSED. Parent: 1.2 - F_TEST [ 0, ENDING] PASSED. Parent: 1.3 - F_TEST [ 0,7fffffffffffffff] PASSED. Parent: 1.4 - F_TEST [ 1, 1] PASSED. Parent: 1.5 - F_TEST [ 1, ENDING] PASSED. Parent: 1.6 - F_TEST [ 1,7fffffffffffffff] PASSED. Parent: 1.7 - F_TEST [7fffffffffffffff, 1] PASSED. Parent: 1.8 - F_TEST [7fffffffffffffff, ENDING] PASSED. Parent: 1.9 - F_TEST [7fffffffffffffff,7fffffffffffffff] PASSED. Test #2 - Try to lock the whole file. Parent: 2.0 - F_TLOCK [ 0, ENDING] PASSED. Child: 2.1 - F_TEST [ 0, 1] FAILED! Child: **** Expected EACCES, returned success... Child: **** Probably implementation error. ** CHILD pass 1 results: 0/0 pass, 0/0 warn, 1/1 fail (pass/total). Parent: Child died ** PARENT pass 1 results: 10/10 pass, 0/0 warn, 0/0 fail (pass/total). After patch: $ ./cthon04/lock/tlocklfs -t 2 /mnt Creating parent/child synchronization pipes. Test #2 - Try to lock the whole file. Parent: 2.0 - F_TLOCK [ 0, ENDING] PASSED. Child: 2.1 - F_TEST [ 0, 1] PASSED. Child: 2.2 - F_TEST [ 0, ENDING] PASSED. Child: 2.3 - F_TEST [ 0,7fffffffffffffff] PASSED. Child: 2.4 - F_TEST [ 1, 1] PASSED. Child: 2.5 - F_TEST [ 1, ENDING] PASSED. Child: 2.6 - F_TEST [ 1,7fffffffffffffff] PASSED. Child: 2.7 - F_TEST [7fffffffffffffff, 1] PASSED. Child: 2.8 - F_TEST [7fffffffffffffff, ENDING] PASSED. Child: 2.9 - F_TEST [7fffffffffffffff,7fffffffffffffff] PASSED. Parent: 2.10 - F_ULOCK [ 0, ENDING] PASSED. ** PARENT pass 1 results: 2/2 pass, 0/0 warn, 0/0 fail (pass/total). ** CHILD pass 1 results: 9/9 pass, 0/0 warn, 0/0 fail (pass/total). Fixes: d80c69846ddf ("cifs: fix signed integer overflow when fl_end is OFFSET_MAX") Reported-by: Xiaoli Feng Cc: Signed-off-by: Paulo Alcantara (SUSE) Signed-off-by: Steve French --- fs/cifs/cifsglob.h | 4 ++-- fs/cifs/file.c | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 3070407cafa7..45a7a4a92643 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -2132,9 +2132,9 @@ static inline bool cifs_is_referral_server(struct cifs_tcon *tcon, return is_tcon_dfs(tcon) || (ref && (ref->flags & DFSREF_REFERRAL_SERVER)); } -static inline u64 cifs_flock_len(struct file_lock *fl) +static inline u64 cifs_flock_len(const struct file_lock *fl) { - return fl->fl_end == OFFSET_MAX ? 0 : fl->fl_end - fl->fl_start + 1; + return fl->fl_end - fl->fl_start + 1; } static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 85f2abcb2795..4ba019c260aa 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1936,9 +1936,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *flock) rc = -EACCES; xid = get_xid(); - cifs_dbg(FYI, "Lock parm: 0x%x flockflags: 0x%x flocktype: 0x%x start: %lld end: %lld\n", - cmd, flock->fl_flags, flock->fl_type, - flock->fl_start, flock->fl_end); + cifs_dbg(FYI, "%s: %pD2 cmd=0x%x type=0x%x flags=0x%x r=%Ld:%Ld\n", __func__, file, cmd, + flock->fl_flags, flock->fl_type, flock->fl_start, flock->fl_end); cfile = (struct cifsFileInfo *)file->private_data; tcon = tlink_tcon(cfile->tlink); -- 2.34.1