From patchwork Fri Dec 17 11:23:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 12684313 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 72EECC433FE for ; Fri, 17 Dec 2021 11:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235339AbhLQLYF (ORCPT ); Fri, 17 Dec 2021 06:24:05 -0500 Received: from mail-eopbgr80130.outbound.protection.outlook.com ([40.107.8.130]:9600 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229797AbhLQLYE (ORCPT ); Fri, 17 Dec 2021 06:24:04 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g4FKMGQWBm8/rue07yydW5LTwPh9oTZ8F4EL4WnyppgsDJG2Ct2SjNvUH9kQmPcXDJz4Ja2z7U4EtZXgM3g8ISliMSxEjv88iMev7lICsfIOQJ0Q3//Gbze6+zq2la9M7l8QaUqRXj5QCusb+84PfDT4uWcrhEyZmT4nCqB74L6NsSo8zg/yeQSz7u+WBeFQdVpfY3oBE4LvSqxywigaSpIWHmfv+msf/qtDNN7JQtlKcWU/uT6azwdlQDF2k+Zcv6+XYob0nHutC/PsMPXFMb1bMWUuIT4vXEkNFwE2hD/Rfn7JiB3Qod6TIg5qrdlWd0K/+CtENjSOAbH4Z22FZQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=04P3EfDuS71L+U52TLsuKVOnNW9WyOOVIv8Rua/8fDQ=; b=WMaa5Pc/r0IpNCbnjYfSlLsR2J8T0gaO/fhq/tfw3G8TrsBiTLgzwjkbX+Q9Hy5AXhToKKClUcU/iRx35x/6S0yuTSN1mwQDukx/s73KIevnYmnFypV4l3Hl8iYzzyDD11LtiYLfvyVQwwCx86fgESlsv89qzZlfGoG7fRbS0qh6j9GaSxoui/lC/bleXsnk8jfKndbRJgl9nY2/YVDVTc2+pQIbtyu/9pRhkU2I357COx9ReBXFpEQGP0+88aszCqceEj15QEIOrs8aoc4zzoiTdOAw9rFx6y13liJ8d+548F1/tLrutHmXtzFDXFbBTzrQb94/1txBUcXbqVFHgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=04P3EfDuS71L+U52TLsuKVOnNW9WyOOVIv8Rua/8fDQ=; b=CPPRvvS25bc2HAb9A2lJauZqcEUHGFpA2jHx3t4cwlg1gPI5Ix6w73fX0YXKlHMG4JtU+2hvHKJQTz7aKTUpqMRlak51p4wnk949KZaAjy+YkvKGTJn6CuOvHJxxujPEn4angWTbVc3ywGIEfEx1YUpfCieJHbOf8RPC5n9W+SU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB6619.eurprd08.prod.outlook.com (2603:10a6:10:257::21) by DB6PR0802MB2311.eurprd08.prod.outlook.com (2603:10a6:4:87::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.17; Fri, 17 Dec 2021 11:24:01 +0000 Received: from DB9PR08MB6619.eurprd08.prod.outlook.com ([fe80::347f:d385:ec53:75aa]) by DB9PR08MB6619.eurprd08.prod.outlook.com ([fe80::347f:d385:ec53:75aa%7]) with mapi id 15.20.4801.015; Fri, 17 Dec 2021 11:24:01 +0000 From: Vasily Averin Subject: [PATCH] ksmbd: force "fail immediately" flag on fs with its own ->lock To: Namjae Jeon , Sergey Senozhatsky , Steve French , Hyunchul Lee Cc: Bruce Fields , Jeff Layton , kernel@openvz.org, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: Date: Fri, 17 Dec 2021 14:23:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 Content-Language: en-US X-ClientProxiedBy: AS9PR04CA0073.eurprd04.prod.outlook.com (2603:10a6:20b:48b::27) To DB9PR08MB6619.eurprd08.prod.outlook.com (2603:10a6:10:257::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1fc7cc7e-bb5f-4e5c-d302-08d9c14fb9c0 X-MS-TrafficTypeDiagnostic: DB6PR0802MB2311:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H1zibnV26rQBdQYWVaJLwp6Hl5wyU3SAtkHkYl0mbVAAXmZA3ijGn4X7WdgyeKx4Rb7rc91+0aCkHJHQUL24HvFozxg+ogn2OntSMzYIovMuJ5/adEXh7P+pF1833t+ns/k6DcG6XP+7H5PkILPNXXVrourKiJk6pov0oXtpGjhOxiycKyCshW4rBpJx4LZrapapz1QVSccBjJoLIs9fhRcc8Xdg6Wmur4eEwmG63m1Nd852HRi6EjSRbeYr5x34A8lGzdlAU+hvjohqtztsiPUP6GthT8LOFvNKzIGNyS2lGYkAr8Zb7KGpiAVxLISMs8JZEn52+zFKvMC2X74hAsWotFHoj0C8Y4Mjfn/GnT69oe4gZP/o8gU4VLwNv6k8bKmAuREcP+hmtP2D8wj7q4huWgdIMitD5RRLA46bccxaCmGIFT+4wOuru4n/EAwsXdE3I1HvNg80BTym02VYearz+YrRdKEeiIUklRYHKQ4rO1pPJGgp2jQraT8hkzVVUI9EO6u778Ay49S3eVgVK1zelW0ZU/+KB51Kv0RjK/YqgbfTWKHQ8YRAW5KC9fRFqiRAQqkCVGv0tKY4xgInYqVmfqMdzz+ZAVczQxx6PsdsVFujSgkOfAHXH6X1cr8QxUtM6KyQt4O/lUk2soqrOXVryhqijzj7QlfJVBo3vL0Y+0wPjKTFmd3gJfWS9mD80Huh5F5H4mzAQ4x8Y+QiU7YhlFNc14YLNplFnNyUBpv1CWa4kYyoqVTXgUddool3YzCuS3I4M8h5wAqulHWajHhz9hIMCCuu3vBYeZYSHKE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR08MB6619.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(66946007)(508600001)(6512007)(36756003)(38100700002)(6486002)(38350700002)(6506007)(52116002)(31696002)(31686004)(26005)(110136005)(316002)(186003)(66476007)(66556008)(54906003)(86362001)(2616005)(8936002)(83380400001)(2906002)(4326008)(5660300002)(8676002)(14773001)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hjWqDHljCk0jZv4CKI4feq8Z1u0M?= =?utf-8?q?NIjB6lQJ+twonSM2BG/V8AcSTVmrc9RsjigDRcyh6iM0sVTHBt+n2R0w7xv15Pa/Y?= =?utf-8?q?JKPndfFdlzVSpZNXCithhW83uszXH92a3mZay7abEa11fveBTbp9dUXvTAEEa2kgv?= =?utf-8?q?iLpepeSAycNjyltXQHe7/PMg9JIxMkVCNqx7/AvlenG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ApsV7wTwbwH3faCdOVPG0l?= =?utf-8?q?qX6rtAWP3Cuos9HTVo/5eSTZz8jm8GR5lEgpSaTFGTdV8bm3fiE21IGK5sILSUAiE?= =?utf-8?q?DA/yLJrcFOB0v/yLUQyZOag+rtIZPoTKjyyUAA1M8rS98/xD4At3je0b6/NzQHuaP?= =?utf-8?q?WawZVxLnWb0CBaoMXXLxIrddgsUQSWqQWSpobfvnB4i64C0U6OhpyNLSyQ0GTR3ul?= =?utf-8?q?1S8xatwULgVKrXtbXV/gZRqNVQpHVh8OPbtLnNamuUCt7X9JUc0SQ64wCHRidHo8c?= =?utf-8?q?2WEMRdhpnHcGfk9qa1VEyjFEHTFkDIUKx2p68aGTtUQ/Gvm2BjnLiUNwzsnQKqvAX?= =?utf-8?q?amWNRFdBqBg321EvaLm7xkPT365sQ7HUHPBXmZOTeedONdnPMtEIOoATccZLKFmSw?= =?utf-8?q?EDn9PfX+rtn5GHwD5+Pyd68JE/Ll6cZGf3SxOjKArQIpgunUhsZUWwSWUqJ5PEwtF?= =?utf-8?q?R63uAlcBXorNw0pfBkKmXI444oBaZCUmN4MzpcGp0FBuve0PZPuvZQo=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1fc7cc7e-bb5f-4e5c-d302-08d9c14fb9c0 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB6619.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2021 11:24:01.4805 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5v6qSBgtf2IM4TPhRis2ceVaoiq24yLieMT6tipubyrRymusfadjVkayhTYfAYA4dM+0yxP3x8kTsyx2k2mpOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2311 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Like nfsd and lockd, ksmbd can cause deadlock if the exported file system does not support asynchronous processing of blocking locks: if all ksmbd worker threads handles such requests, they can never finish and the server will not be able to handle any other incoming requests. Any filesystem that leaves ->lock NULL will use posix_lock_file(), which does the right thing. Simplest is just to assume that any filesystem that defines its own ->lock is not safe to request a blocking lock from. To work around the problem we need to drop fl->fl_flag FL_SLEEP before vfs_lock_file() execution, it forces affected functions to avoid blocking. Signed-off-by: Vasily Averin Acked-by: Namjae Jeon --- fs/ksmbd/smb2pdu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index 121f8e8c70ac..f2225491af02 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -6634,6 +6634,12 @@ static int smb2_set_flock_flags(struct file_lock *flock, int flags) { int cmd = -EINVAL; + if ((flock->fl_file->f_op->lock) && + ((flags == SMB2_LOCKFLAG_SHARED) || + (flags == SMB2_LOCKFLAG_EXCLUSIVE))) { + ksmbd_debug(SMB, "force fail immediately request\n"); + flags |= SMB2_LOCKFLAG_FAIL_IMMEDIATELY; + } /* Checking for wrong flag combination during lock request*/ switch (flags) { case SMB2_LOCKFLAG_SHARED: