Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1310068rwi; Thu, 13 Oct 2022 11:50:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7jBkEl3TVrFxBM2yFaQiiq9FP6VMdQy7Mv9l1bbaItwqkM60g5VhRrKrkO9ZIo4vYIlauA X-Received: by 2002:a17:90a:d518:b0:20d:516d:67ee with SMTP id t24-20020a17090ad51800b0020d516d67eemr1308148pju.9.1665687055407; Thu, 13 Oct 2022 11:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665687055; cv=none; d=google.com; s=arc-20160816; b=W0vDdX3e8RhWLfaK728eAiqz39Mqlvaxn3+yDprMBEVHlsZ8UEeGGXXOI5KCoXVobL v/FXLO+aUii6Q8N5Jo9vblmm/Rnmwdj+sF5+hJqR2T7dm5bnwsSVwshhhamzLlmHdmJN LHh4upW6Nr5REjtNBAwHEM3sFg9jua/iDqkD6YhOSjOenCv4NM2hv7J4neiXjPMciqeb tj0YB5W9Y2s5uj5+z5Ko83nHQg9YFZ7NA8FRgAaJPSNEYqYhs1p3metRJA6yhN0qDXi5 vKubf2kfVeGkbC7c9bPEIefNSYxgH8fn3KsCuSCy6idzxc8F6KlDkxq7ecws7p8YfL4n v9cA== 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=Y51dPL2dJcW8XornZKwyih6E7MaPSTDNxdV4RZ67VRc=; b=Pg3mFQDpQeKxmf9qWvHol37XDptkTrPYbsUTJXM/gaUb9fRRQhL8qhrwIlcXvaPTRx LzvUkxGAT1M346agcUhAiwVOjE+2ESxEtdI2fQ0MUEnD8RxUqT49JqIIS6aVp6oaXAjS v4sdiBvekR/DxEhFgsNYUQQvQoIK62/+JPchr862pncQjxihxDiqMIXVh9/+H6t9WaJs PXoSWsLY6O2yrCI4UDNcwhINB2+d45KegPBkYsFoxwHAH28DOaF2ERzk7c69MP85+bDb h35HZ6RZCv8Uye8GAesy5UBUNf06AKpkzPj4l9F/QMy7P1/7enxJ/g4gkqtFq4LXlyvQ 7OSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OgCHOc6R; 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 k9-20020a170902c40900b0017d2311af5dsi627454plk.69.2022.10.13.11.50.43; Thu, 13 Oct 2022 11:50:55 -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=OgCHOc6R; 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 S231578AbiJMSH2 (ORCPT + 99 others); Thu, 13 Oct 2022 14:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231197AbiJMSFh (ORCPT ); Thu, 13 Oct 2022 14:05:37 -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 B3F15286F3; Thu, 13 Oct 2022 11:04:49 -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 8D278B82051; Thu, 13 Oct 2022 17:58:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFA1AC43147; Thu, 13 Oct 2022 17:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683913; bh=/ENOfpenacNUYYlNZFJ88DSGQqTjUSJmaDxMQfCiVZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgCHOc6R5vhgK6fUQCNEPYEwOQjJe1IfVVwPEt1RrD5XPeXUjPGKrY9riwVVDwxoQ iYNZNCJPrJDE/4W/XI7RaViG3DBbHAsYKtRvkAq3h4hXl8MO22T1mFrUTm3VIU+byj c8spqCC650WuobdzZpnUKV4wmgHMpQ6ro68lpFJ8= 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 5.15 05/27] ceph: dont truncate file in atomic_open Date: Thu, 13 Oct 2022 19:52:34 +0200 Message-Id: <20221013175143.724210164@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175143.518476113@linuxfoundation.org> References: <20221013175143.518476113@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.1 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 5.19 backport] Signed-off-by: Xiubo Li Signed-off-by: Greg Kroah-Hartman --- fs/ceph/file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -703,6 +703,12 @@ int ceph_atomic_open(struct inode *dir, if (dentry->d_name.len > NAME_MAX) return -ENAMETOOLONG; + /* + * 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) { if (ceph_quota_is_max_files_exceeded(dir)) return -EDQUOT; @@ -770,9 +776,7 @@ retry: } set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); - 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); if (err == -ENOENT) { dentry = ceph_handle_snapdir(req, dentry); if (IS_ERR(dentry)) {