From mboxrd@z Thu Jan 1 00:00:00 1970 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 3F525C6FD1D for ; Mon, 20 Mar 2023 12:49:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231642AbjCTMtF (ORCPT ); Mon, 20 Mar 2023 08:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231653AbjCTMsW (ORCPT ); Mon, 20 Mar 2023 08:48:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D463144BF for ; Mon, 20 Mar 2023 05:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679316447; 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: in-reply-to:in-reply-to:references:references; bh=MCTZ2YEpD+DNcu1eqCJ1wevQ6rnwTmcbdNFcopJE5v0=; b=Bu2VlutiK2wHeVMCGuP7QKn+J7sLVpDFjOkItxqmiR50WS55wP2qlil8zGCmn+BXd0EXCR TE4La+nmhjr7swh3MPPcldhZHxdlkySTS1oqiQn543Nui6Kj9PYwT0Z5b0nh6dnWy/YsFc SrGBpImNzVFWVbiKVAYu2IaJAQ/IbHM= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-147-i3hEmAttP6SaApDMMI3yzg-1; Mon, 20 Mar 2023 08:47:25 -0400 X-MC-Unique: i3hEmAttP6SaApDMMI3yzg-1 Received: by mail-pf1-f200.google.com with SMTP id x3-20020a62fb03000000b00622df3f5d0cso6250218pfm.10 for ; Mon, 20 Mar 2023 05:47:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679316445; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MCTZ2YEpD+DNcu1eqCJ1wevQ6rnwTmcbdNFcopJE5v0=; b=kn2RYF6UtGOs4FYFosPX4gNJ2ZkTLbmuVBMHzbOjYaAONMsaOUfIDyRGaphLML9nMs 90EzXUUT70fvC7VPb9NE70CcWaosI9q0e2Fmf1TyOQ1QHVegLpCJ+NN6XiDGxLvHGwBi hdSHXwcmnqAX2nrvggwG/0JHfn+L7xnNY5fuCN2MljPLF5fPiHF8UkEcHTSIWrME67fS 2/I8o9QqnjD4q05K0aJn+HkbGtM9hKxTzTV3/cciHuwLrf1v+e6QXUHI6bWWe5xXALLI pXrCQXmhAFKY2WMHWipVALG9xUS6ICMugP8uhjiHqf2Kq7GxNRot9dwscFAy1Ijrd38E Jitw== X-Gm-Message-State: AO0yUKUCk14jJUw7BYs3sB3lDuOgiY2KZ6bAVbcx47oy/RMAjc0ihmAa ug35YI0DDPsNiloVnFcYn7KUmDGLxusXCGzS3GhfmULl/Xcy1HvmLI3QwOm9fGE4v8wu+IB1EIT COqeN053BTfoPTXzUlD9wQg== X-Received: by 2002:a17:90a:354:b0:233:ee67:8eb3 with SMTP id 20-20020a17090a035400b00233ee678eb3mr20113191pjf.24.1679316444861; Mon, 20 Mar 2023 05:47:24 -0700 (PDT) X-Google-Smtp-Source: AK7set9NvQjuWxOqxvHTyhzTOo2bI7ogfxl2dHPoaHJN+qRIYINNczfbWhlBBbuhETGfpifCCMiNgw== X-Received: by 2002:a17:90a:354:b0:233:ee67:8eb3 with SMTP id 20-20020a17090a035400b00233ee678eb3mr20113160pjf.24.1679316444444; Mon, 20 Mar 2023 05:47:24 -0700 (PDT) Received: from [10.72.12.59] ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id gq21-20020a17090b105500b002342ccc8280sm6176676pjb.6.2023.03.20.05.47.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Mar 2023 05:47:24 -0700 (PDT) Message-ID: <0b51da52-bb38-2094-b9b2-bc3858066be5@redhat.com> Date: Mon, 20 Mar 2023 20:47:18 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v3 0/3] ceph: fscrypt: fix atomic open bug for encrypted directories Content-Language: en-US To: Ilya Dryomov Cc: =?UTF-8?Q?Lu=c3=ads_Henriques?= , Eric Biggers , Jeff Layton , "Theodore Y. Ts'o" , Jaegeuk Kim , linux-fscrypt@vger.kernel.org, ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230316181413.26916-1-lhenriques@suse.de> <568da52f-18a6-5f96-cd51-5b07dedefb2d@redhat.com> From: Xiubo Li In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org On 20/03/2023 19:20, Ilya Dryomov wrote: > On Mon, Mar 20, 2023 at 2:07 AM Xiubo Li wrote: >> >> On 17/03/2023 02:14, Luís Henriques wrote: >>> Hi! >>> >>> I started seeing fstest generic/123 failing in ceph fscrypt, when running it >>> with 'test_dummy_encryption'. This test is quite simple: >>> >>> 1. Creates a directory with write permissions for root only >>> 2. Writes into a file in that directory >>> 3. Uses 'su' to try to modify that file as a different user, and >>> gets -EPERM >>> >>> All the test steps succeed, but the test fails to cleanup: 'rm -rf ' >>> will fail with -ENOTEMPTY. 'strace' shows that calling unlinkat() to remove >>> the file got a -ENOENT and then -ENOTEMPTY for the directory. >>> >>> This is because 'su' does a drop_caches ('su (874): drop_caches: 2' in >>> dmesg), and ceph's atomic open will do: >>> >>> if (IS_ENCRYPTED(dir)) { >>> set_bit(CEPH_MDS_R_FSCRYPT_FILE, &req->r_req_flags); >>> if (!fscrypt_has_encryption_key(dir)) { >>> spin_lock(&dentry->d_lock); >>> dentry->d_flags |= DCACHE_NOKEY_NAME; >>> spin_unlock(&dentry->d_lock); >>> } >>> } >>> >>> Although 'dir' has the encryption key available, fscrypt_has_encryption_key() >>> will return 'false' because fscrypt info isn't yet set after the cache >>> cleanup. >>> >>> The first patch will add a new helper for the atomic_open that will force >>> the fscrypt info to be loaded into an inode that has been evicted recently >>> but for which the key is still available. >>> >>> The second patch switches ceph atomic_open to use the new fscrypt helper. >>> >>> Cheers, >>> -- >>> Luís >>> >>> Changes since v2: >>> - Make helper more generic and to be used both in lookup and atomic open >>> operations >>> - Modify ceph_lookup (patch 0002) and ceph_atomic_open (patch 0003) to use >>> the new helper >>> >>> Changes since v1: >>> - Dropped IS_ENCRYPTED() from helper function because kerneldoc says >>> already that it applies to encrypted directories and, most importantly, >>> because it would introduce a different behaviour for >>> CONFIG_FS_ENCRYPTION and !CONFIG_FS_ENCRYPTION. >>> - Rephrased helper kerneldoc >>> >>> Changes since initial RFC (after Eric's review): >>> - Added kerneldoc comments to the new fscrypt helper >>> - Dropped '__' from helper name (now fscrypt_prepare_atomic_open()) >>> - Added IS_ENCRYPTED() check in helper >>> - DCACHE_NOKEY_NAME is not set if fscrypt_get_encryption_info() returns an >>> error >>> - Fixed helper for !CONFIG_FS_ENCRYPTION (now defined 'static inline') >> This series looks good to me. >> >> And I have run the test locally and worked well. >> >> >>> Luís Henriques (3): >>> fscrypt: new helper function - fscrypt_prepare_lookup_partial() >> Eric, >> >> If possible I we can pick this together to ceph repo and need your ack >> about this. Or you can pick it to the crypto repo then please feel free >> to add: >> >> Tested-by: Xiubo Li and Reviewed-by: Xiubo Li >> > I would prefer the fscrypt helper to go through the fscrypt tree. Sure. This also LGTM. Thanks - Xiubo > Thanks, > > Ilya >