From patchwork Tue Feb 23 18:27:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Aur=C3=A9lien_Aptel?= X-Patchwork-Id: 12100715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D449C433E6 for ; Tue, 23 Feb 2021 18:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1B6864E6B for ; Tue, 23 Feb 2021 18:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233128AbhBWS2r (ORCPT ); Tue, 23 Feb 2021 13:28:47 -0500 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:30300 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233900AbhBWS2q (ORCPT ); Tue, 23 Feb 2021 13:28:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1614104851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=anpaLtEcd3qtkAoA/Wm8hrwTV46F/traBfj2tarUVHU=; b=RUKRrfb2QN2wX+X2a9+v6XvEQ4kAw1JEDSVllk/k8/HbqCtktgvuaNNoTrsKaC4FsiE5gi A/E45yxA3qqAGV4oGWyj0yjPB3QpfWeyeu607SnwDORutf0bDV3dOaDGwZRM7TgJ7oj7Ev 2iar3+vqoe5FidlT7UbYhCm4gna+wqU= Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04lp2058.outbound.protection.outlook.com [104.47.12.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-9-U9RgydIDOl6GTeJjcfNK2w-1; Tue, 23 Feb 2021 19:27:30 +0100 X-MC-Unique: U9RgydIDOl6GTeJjcfNK2w-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U9XfZHdjDBpfa1TIhdkbXSMBbrvqJputfyHFgMjJnIUXWKYt2/cFAJezkTI2O33y5O0Favv5um4DJG54fTu5PIhRWS7ZhiVaNrMGetGWuz3Watrrh8rlbDGAK1szqaWxvUltbdADoDp2oQTT3EgHs2lo5kDU/EbPgAcEjo+j8H8oKpY/rfWbs+nE0PiIV+Kp2Okcel0ddTD+00EpRynlax21+/Z0//yp7YXy5Xh2cUOo+9VDac99CnuEI8+UQAjKIi6uTF8yckg1cccTaCbsesiOij0/z6fPTv4JLy4QJJnMHmXGBdav7hN/i8x8U7pWj7ZpC6/RatMbwzEuEqDBMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fJhH+wC6DS/hHrW/UeAnXR7v5GsP377h4BKSIAVDhAU=; b=FJmtIASCv97u1T5GPvSvfnJUM9MPy1+XIP7sDh/8Gi2FiwXrFSt8s1JBCWjgPHxvg13F5It9jZ0Msnw14nZUMpAgAHqi1gSx9jXBWVXQSYro9uUFwWo/xELOaTm7O/9Yzreh83hyK5WLgS1GkZYk4k1wkjT/iOTGaxgwwh2r7MjWjNrpJPvQE9Quzu5PGNoFVw4gmbiKDWyC4IgKW9sEJNvciJKWTk5nPF/zL/ULH2JF9y41bogdiyBi5MLET1abkQgerwWhlPVuP/6c01aRAnkFmvol5SqLCZx84Inf7A0qvbhZnK+0G4wl2tp8s0yaZFxDS8kdyM7KVBCJA24P4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3359.eurprd04.prod.outlook.com (2603:10a6:803:3::28) by VE1PR04MB7277.eurprd04.prod.outlook.com (2603:10a6:800:1b3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3868.32; Tue, 23 Feb 2021 18:27:29 +0000 Received: from VI1PR0402MB3359.eurprd04.prod.outlook.com ([fe80::9c1d:89de:a08e:ccc9]) by VI1PR0402MB3359.eurprd04.prod.outlook.com ([fe80::9c1d:89de:a08e:ccc9%4]) with mapi id 15.20.3868.032; Tue, 23 Feb 2021 18:27:29 +0000 From: =?utf-8?q?Aur=C3=A9lien_Aptel?= To: linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org CC: smfrench@gmail.com, Aurelien Aptel Subject: [PATCH] cifs: ignore FL_FLOCK locks in read/write Date: Tue, 23 Feb 2021 19:27:26 +0100 Message-ID: <20210223182726.31763-1-aaptel@suse.com> X-Mailer: git-send-email 2.30.0 X-Originating-IP: [2003:fa:705:9b31:db:7402:52ee:d004] X-ClientProxiedBy: ZRAP278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::12) To VI1PR0402MB3359.eurprd04.prod.outlook.com (2603:10a6:803:3::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (2003:fa:705:9b31:db:7402:52ee:d004) by ZRAP278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Tue, 23 Feb 2021 18:27:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e4d39ac5-f496-403d-d92a-08d8d828ad5e X-MS-TrafficTypeDiagnostic: VE1PR04MB7277: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qdxyfE8Jh6BMAAnN+t+B//uIGGS3sf19F/8sT1nv8rVcWuZymVWnbunVJ2Bl/KdNSYlJNXEoi98Kx47PEyTnl1x8M2dsWocTs5h+uSheq588GqC3ueWJTT2atT1lDBfjFRMWrGjOVbUVM++/VyWFb7siZf1Y8eIBlZBpanFDCAs94kC9Zmbx0QKxPYZi1j/XJ5m3FpZkkaHnAkx4+SGLa4+kZPKYYqIXPAxztsH7hNtP8zWXxPQ4iGGhzEXDo2MOmin4lUyGlPm4M5DAtEPZtDr/gpmp7evyADVDghlJNJ5g1YVQNaCLwbPXZAoz/YPML6mrt78XNyDHx8C7N7yfnvlWsr4jHvEI3uc50ti2BDFzIhRzLeoVt+JAYwTqNBgzvec/2PBMWzii1N6tj/1YfWIt817+g9FZDWGENKd9OZSzUdiw9dr6phJraxSVTxBhGoAg5Cp2itRutLLEAcO9N9sHU6DsesE4rcq76Nx2z/D4LNB9R68ZcthAY9d9f9N3r9W2/YRd+ZwiwZJVm3EDmBfnvtlvHRJAz1TabjJWNfV/ELuHjABIbvprTx63qPVaL/fho1JEXc6Dw7QmPEZUyyJqsmzQ6hGD/DNnoMTGpXe1Zy97z2I8UD+VRRPNEFE6oDx8EIVw/ax4P5km4gjwV3OvXSaAG6exBMewHmhnthAAY9lCUtbRPqh9A62TZvLdnZsahLuZr5p9wbb9AYLuQCzKFgNW6GqD88f2nibYL+SSOpHjTp5wk6G9AQ9KzIDkLQs7RMWimRxCXtauu7fhs18uNvDwWBR8C7EoRsY2BMs8BiKY1vqfqQFtZ0EEhy3MpBwZ+X8JRp0N72kr0oGXvYU7mjBPepTb80Bn6/qYo/XtjRQKxn0Nlm1Wm/decnp9De5O53JD1XWyeHwf/ecXYg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:5;SRV:;IPV:NLI;SFV:SPM;H:VI1PR0402MB3359.eurprd04.prod.outlook.com;PTR:;CAT:OSPM;SFS:(396003)(39850400004)(366004)(346002)(136003)(376002)(6666004)(66476007)(2906002)(4326008)(8676002)(6486002)(66556008)(186003)(16526019)(478600001)(8936002)(66946007)(6496006)(316002)(5660300002)(107886003)(52116002)(2616005)(1076003)(86362001)(83380400001)(36756003)(23200700001);DIR:OUT;SFP:1501; X-MS-Exchange-AntiSpam-MessageData: P6eGyymz+ngnS4L3Rebl2bMRmki2e1shlKOl/yKhLSdLQPNIe5lXBnfvz0SDlLbz09e//btaxzblOUQfrSvV2lQ5JDE0zplKd7g9fTOUmv0wC90FsMxpj90h0KceexsMbLkDmD7T3bZ0K0fPTfe0GVON3L3m1jysqAPO73+lJLmAGpXy3rC7LDei3TVEDA6e0HGe1KknUP9+UFLf3Y6MMqz66ihMmvpEdo+V4mJ9cVb/5zrqg2d5PBZEhHwL71KxAU+Et3ngwtxh5pgcxceG8iQNN2GriO2RnYnXdv9DrYUL54r86yVJm/10suV7KnWJBvgdSlYVeHO7jPu6P+NVi/6ltxMrdHeNjiE+9ps68yd3FNi8O+V+Y754xdlEZ93XXZDwfyln2j8OyU9+VOmiqEqqkQwtwGnYHWrymmR2JVjIZwdinXD/TF0sxLLSHMHtXJzSU1S00BXT21F9b5YG+MGU1exxS4+2+gApGK08kzI3HOIVDSoCm99dzNnrtRydogJlSwv0c9v2rsq2ZwZcLnin6SP6KlDOWx2fQH4BXcg6tdd9iJhvJ4ERzZTTnP1swD4C/MM+JIUng+wXsyCLROk+6MErEF1jqfsj/6wS9yrIh/Aa8Vrxi1o/1dOscgyIBGFrRqeQKxIloU7+OX1Lq10udADnbTariFt6kfzUSBnwR4j6Y6/yPy0r/vnsPD+j8vYQu9oc57+9St7pS4ZEH4ySjj/V3gReHX9NDmJ3F77AU+vfCOeuXeJaBc/7K/XzkRgFxuSJzlBJIHtS6yDgR5TadZ+ls8q++ncyBsEItXbBpqkFxvnBCQ1bj7ktI1eaaU1IbrFPrTC0qkIAhEjNtCVTC0/TJpq3QlC+1g5qWDpgx1Yc0ydQno6nwLHKsYUkP/bXfTiv0JHeTs3ULuHHSMHauBTRSDwsrGKtEXMPXM0dtk5bOAAoKT1p3t3T8zTPsSqf4R4oUPXkvmgTw/Pr4fasFk04OwMwK0/c4bE18BzlRKS1BPZa91i/bgxIXypti7md1V5C7S0etNw3xc3+o4QUimf7AEQXek4IeCaJW6rwt04MZAv3oYn//FgNxD5lJAcNIvnc/Hg1+n83OgO6oi+YRAB4Yz2IfpYH+VONSZewhG9eVk0WQbs+44IuJCBOIF9ZYTDvtCng0VmABMsFftqTNjXqzDxbMBkeq25e4BZ7VmcvLPAX/KHZv0LSlwPo57XjZSAdO8Jtpq0GIl8Rm0nTUuqWQD6eoeOEWY1K12DrZWEATuYRfyL723j2DS5BdvGiZlLlsKkVdYpuVYYvIjNbKypDhYDjFD85hl4y8U/OnlGIXsOQd+DDtXOmp11gwzTYTa5+f7/cbIW58eoyJJBA+DTWKTWz939i0/VN49SOy5T74eFRsoyfhkghtALS X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4d39ac5-f496-403d-d92a-08d8d828ad5e X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3359.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2021 18:27:29.2930 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JzLyX9nSkVMmAQequ1gasUbTU2LNgkqoEM7mn7qRZCx1Up0vqfot/3DnAz3uaLnQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7277 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org From: Aurelien Aptel flock(2)-type locks are advisory, they are not supposed to prevent IO if mode would otherwise allow it. From man page: flock() places advisory locks only; given suitable permissions on a file, a process is free to ignore the use of flock() and perform I/O on the file. Simple reproducer: #include #include #include #include #include #include #include int main(int argc, char** argv) { const char* fn = argv[1] ? argv[1] : "aaa"; int fd, status, rc; pid_t pid; fd = open(fn, O_RDWR|O_CREAT, S_IRWXU); pid = fork(); if (pid == 0) { flock(fd, LOCK_SH); exit(0); } waitpid(pid, &status, 0); rc = write(fd, "xxx\n", 4); if (rc < 0) { perror("write"); return 1; } puts("ok"); return 0; } If the locks are advisory the write() call is supposed to work otherwise we are trying to write with only a read lock (aka shared lock) so it fails. Signed-off-by: Aurelien Aptel --- fs/cifs/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 6d001905c8e5..3e351a534720 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -3242,6 +3242,7 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from) struct inode *inode = file->f_mapping->host; struct cifsInodeInfo *cinode = CIFS_I(inode); struct TCP_Server_Info *server = tlink_tcon(cfile->tlink)->ses->server; + struct cifsLockInfo *lock; ssize_t rc; inode_lock(inode); @@ -3257,7 +3258,7 @@ cifs_writev(struct kiocb *iocb, struct iov_iter *from) if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(from), server->vals->exclusive_lock_type, 0, - NULL, CIFS_WRITE_OP)) + &lock, CIFS_WRITE_OP) || (lock->flags & FL_FLOCK)) rc = __generic_file_write_iter(iocb, from); else rc = -EACCES; @@ -3975,6 +3976,7 @@ cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to) struct cifsFileInfo *cfile = (struct cifsFileInfo *) iocb->ki_filp->private_data; struct cifs_tcon *tcon = tlink_tcon(cfile->tlink); + struct cifsLockInfo *lock; int rc = -EACCES; /* @@ -4000,7 +4002,7 @@ cifs_strict_readv(struct kiocb *iocb, struct iov_iter *to) down_read(&cinode->lock_sem); if (!cifs_find_lock_conflict(cfile, iocb->ki_pos, iov_iter_count(to), tcon->ses->server->vals->shared_lock_type, - 0, NULL, CIFS_READ_OP)) + 0, &lock, CIFS_READ_OP) || (lock->flags & FL_FLOCK)) rc = generic_file_read_iter(iocb, to); up_read(&cinode->lock_sem); return rc;