From patchwork Mon Oct 24 11:29:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp429412wru; Mon, 24 Oct 2022 05:38:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4QcLB7FWBffoqJyE6mWwJacUoKX3YslcJQLCdRW+RKRJj6ufQllzD6m2qat+/F8096DW4x X-Received: by 2002:a17:90b:4b0e:b0:213:227d:14a6 with SMTP id lx14-20020a17090b4b0e00b00213227d14a6mr2469678pjb.12.1666615115213; Mon, 24 Oct 2022 05:38:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615115; cv=none; d=google.com; s=arc-20160816; b=zQoI8KxFgdPyU97g7TtqlPY5IsoLdPtb9QyqW77BLdvsMN038Pnr+XuCz8n6Msqm56 37UPFuV3tKcz6E+MwOqgFVVJBSuyvsV/VgTyU3MHNW3znAk09Q+D/mpkLluZGRKQ1OUt k29lhm0RhGv1slJk8Vry0IpnVJRc3Yggn2loPootUSJOsHm+gCgGr2zo7TTXHLgzMNDx wchcbBbrwRzXEvWpJZSziUnC0uS8Mrfr8QATl0+QbooYkXpL1iLeOIUvxnJFnHUHywjY 8mBQuyxhWltWAJe2Z4qeI3NA8DfF9X3Y7krhojh9wgywCVR2+2TR5X7smHeVGOiltV8J RGOQ== 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=dJB1TNAwpSIGMKtGOJmie6C3pP9ZykNtr2lYIJXUxe4=; b=Ik3k7PRKWqKLLz3H+hlQyT0yzoOWuZqvaiTa6WcUBX/rM82E+DOi6dCQ3jFZrgAZH1 EUg9PcKb+UQPGBEN554ZTec5pJ5QE3IjSF2fPhYw0EbNAgPUtM6huFNFBeheL1VfJ4xb LWb3Xx3ieldCnAQH9598sSSMUJwJXP9tqgQKP4tTFQGLMgkC8/JeaHCJYE9A3kh0I2vv 0u/CNQMyqZC/bjrFK9vUXpIBJuv3oUhatyataiPHyGKUKKH+fnhQrBi1zdWm1sDvejqo SC4iI++Kav5AJfSSvmnT45SlE+aFh01i1KnoI4jjDlsK1voy+Z60zNPYzX667hYMhhOF PMzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J3Nw2quF; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d20-20020a056a00199400b00563b7ea2d7fsi8425114pfl.144.2022.10.24.05.38.22; Mon, 24 Oct 2022 05:38:35 -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=J3Nw2quF; 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 S233692AbiJXM1r (ORCPT + 99 others); Mon, 24 Oct 2022 08:27:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230323AbiJXM07 (ORCPT ); Mon, 24 Oct 2022 08:26:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4146855A9; Mon, 24 Oct 2022 05:01:17 -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 ams.source.kernel.org (Postfix) with ESMTPS id 4E005B8114A; Mon, 24 Oct 2022 11:39:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC687C433D6; Mon, 24 Oct 2022 11:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611572; bh=89u/RKNk6aKgLaW27g8p2OhkdxTPjr9yb5zFZbtSKWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J3Nw2quFTpnqX4LI3MujVO2aVV5LOT+1ffeXMdPFajPUElWSxeQeDY24L9tpY74aP I7nswtOHjHRTRxWxux/1+lw4TBUx8h9U3cEePesVIXOmRLImzqfqSz0pCI/opDTTdZ zZSC1X2sP4J3dfNnHCYySFzR1gxObrs3BACp5yms= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hu Weiwen , Xiubo Li , Ilya Dryomov Subject: [PATCH 4.9 030/159] ceph: dont truncate file in atomic_open Date: Mon, 24 Oct 2022 13:29:44 +0200 Message-Id: <20221024112950.514548543@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747572610781133775?= X-GMAIL-MSGID: =?utf-8?q?1747572610781133775?= From: Hu Weiwen commit 7cb9994754f8a36ae9e5ec4597c5c4c2d6c03832 upstream. Clear O_TRUNC from the flags sent in the MDS create request. `atomic_open' is called before permission check. We should not do any modification to the file here. The caller will do the truncation afterward. Fixes: 124e68e74099 ("ceph: file operations") Signed-off-by: Hu Weiwen Reviewed-by: Xiubo Li Signed-off-by: Ilya Dryomov [Xiubo: fixed a trivial conflict for 4.9 backport] Signed-off-by: Xiubo Li Signed-off-by: Greg Kroah-Hartman --- fs/ceph/file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -354,6 +354,11 @@ int ceph_atomic_open(struct inode *dir, err = ceph_init_dentry(dentry); if (err < 0) return err; + /* + * Do not truncate the file, since atomic_open is called before the + * permission check. The caller will do the truncation afterward. + */ + flags &= ~O_TRUNC; if (flags & O_CREAT) { err = ceph_pre_init_acls(dir, &mode, &acls); @@ -384,9 +389,7 @@ int ceph_atomic_open(struct inode *dir, req->r_args.open.mask = cpu_to_le32(mask); req->r_locked_dir = dir; /* caller holds dir->i_mutex */ - err = ceph_mdsc_do_request(mdsc, - (flags & (O_CREAT|O_TRUNC)) ? dir : NULL, - req); + err = ceph_mdsc_do_request(mdsc, (flags & O_CREAT) ? dir : NULL, req); err = ceph_handle_snapdir(req, dentry, err); if (err) goto out_req;