Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6809880rwi; Mon, 24 Oct 2022 06:26:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7iDhq9Xz7E4SSQ7FUep5Uxz3q92c0ZqKOM1o8yUkZQ0lqNmcB2H5Nu+Xpmuunu7dJP03sS X-Received: by 2002:a05:6402:428d:b0:460:b26c:82a5 with SMTP id g13-20020a056402428d00b00460b26c82a5mr21018476edc.66.1666618002041; Mon, 24 Oct 2022 06:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618002; cv=none; d=google.com; s=arc-20160816; b=y2fOKdgPsSB0v64RNLwOsv2MgwHqG0MUcZTGVGqABANPYQxBwqxm/JnIemg3fbo+0w sD9QAIlIqq0QhKHxF0M+tjyojpoI090VE30NxldG6sj9wR485YMmyC505r2HjyI4lPab /nerOFkj0KMaA58czvwNcv2rNx4AKANe5Es+t1h56gh2nV5cjQr8hlF8/1TPW31v87yF Vi9PHQM7VdG9i4WcL1byFdg/BjZyWum8kbAeG+21fav1UuVvzYKWCTs7UrnydPDjIIh+ y3wlVl4JJGuVLYaRHrwWe1MmZQ3TYZwLU7AbdXHwvo9kyS7+xCJmVZ2/mvsmpx1lSxaj N4xg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a170906288300b0073d9c412570si22872711ejd.785.2022.10.24.06.26.16; Mon, 24 Oct 2022 06:26:42 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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;