Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3097424rwb; Mon, 15 Aug 2022 18:03:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR6tNaLjzP+V3JScoj1t2zexjA4bDy5kuZjIHAZOVil4egU6bGUCQaJEfBAPo9mp/Rf2q9fM X-Received: by 2002:a17:906:99c1:b0:6fe:b01d:134 with SMTP id s1-20020a17090699c100b006feb01d0134mr11719726ejn.598.1660611787981; Mon, 15 Aug 2022 18:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611787; cv=none; d=google.com; s=arc-20160816; b=tbJ0dZZT01vwDd91YKRjnT2cddN1S1jwJJWKUUQDGDCsYiazSMQKurwunya2uoVP5t eY8cdea/OGSBi/FLfJ46sBF2zRw8/XZfpBLv6cTdUzvzmMTFDKlgybbvmHvjViOmfipH 3JQ89dbnC7Bh4H6JOAbsHj0qzf16P2jy3CxXh4I2fEirtuKlRvZpNeGpWcwMgtPgKtUq hLHV6csShsdLxRnyuw2ivNAMcLx5Xx11YHR79fL+fTbma1gPvbX6ukwKskNtYLtSEeYB /9w0oCzaNcKLoFb8ndGEohZ6R60wKD4CQ68CncD7lRfhpl8kfV+/2rzDlEUmHkCNp28g 6Nrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZIKwbcLOjMRp1MAKj2o9TEcntd5mFGX1cGEUH+hfc4M=; b=r5/e70MgXFkSo5tO4HEujDk+yNZmWOjmTdiceddco5ujRJt7S//Css2krXUJVYInir CsUcZ+oSffGbvnpHc/msrL53zGAfIH8t52Pbpvmq7wO4VWvrw/0MuTl4DfCIsNKWDf1R AJY6GkESDE5v7F249vXrE5vCiGDop48nMk3kYkbBNPPeeIGuFRvpeIYwofI9WuQVflmi /xUpm2AjPMnn9m/wpyBBkzqt/gBPBUBqoZNxawwdAZzda0dQ46iBDXrDymxgvWkfw8s7 0ySudEZ3GkoAbzjW3PdPkSTPqrbwEe40g1IumTZcqA7Sgu4jlXJ3liKDvw/+Ub5U8s7b qEKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ynBC6I43; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho39-20020a1709070ea700b007307bd9033esi10923159ejc.972.2022.08.15.18.02.41; Mon, 15 Aug 2022 18:03:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ynBC6I43; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245149AbiHPAz6 (ORCPT + 99 others); Mon, 15 Aug 2022 20:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244269AbiHPAtK (ORCPT ); Mon, 15 Aug 2022 20:49:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF4CBB603B; Mon, 15 Aug 2022 13:46:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E238C61241; Mon, 15 Aug 2022 20:46:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2DACC433C1; Mon, 15 Aug 2022 20:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596382; bh=CPaFUPaj3NVtsuDxVI0hezS2wWYQlJAYNKy5/DDGMgk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ynBC6I43z0LE82FeDx21BBsWAEF7tkY/Wwul78TB2v4wGPskyfLhlUzrVNpqHKKew CYqIZITQXZyuXykn1yvn3arQ5nG3XrrICX+gW8uWqFqOC3qWw2eXrdL1Y6FWWzpjEP sZterP45916+H5m64ihboaQgzmzfDKBtX/mw95p8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoli Feng , "Paulo Alcantara (SUSE)" , Ronnie Sahlberg , Steve French Subject: [PATCH 5.19 1045/1157] cifs: fix lock length calculation Date: Mon, 15 Aug 2022 20:06:41 +0200 Message-Id: <20220815180521.834544546@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paulo Alcantara commit 773891ffd4d628d05c4e22f34541e4779ee7a076 upstream. 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) Reviewed-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifsglob.h | 4 ++-- fs/cifs/file.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -2085,9 +2085,9 @@ static inline bool cifs_is_referral_serv 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 (u64)fl->fl_end - fl->fl_start + 1; } static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses) --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1861,9 +1861,9 @@ int cifs_lock(struct file *file, int cmd 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=%lld:%lld\n", __func__, file, cmd, + flock->fl_flags, flock->fl_type, (long long)flock->fl_start, + (long long)flock->fl_end); cfile = (struct cifsFileInfo *)file->private_data; tcon = tlink_tcon(cfile->tlink);