From patchwork Thu Oct 13 17:52:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2219 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp411164wrs; Thu, 13 Oct 2022 11:08:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59XAIX4AFOnmoYBQsOI7cV0LCjJzTPtYybZItiNCvVIieOO3ELtANoPH0fzorpTzDpSkRC X-Received: by 2002:a63:470b:0:b0:442:24d7:578 with SMTP id u11-20020a63470b000000b0044224d70578mr1014665pga.198.1665684488242; Thu, 13 Oct 2022 11:08:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684488; cv=none; d=google.com; s=arc-20160816; b=PioiUoMchlUZEqDsYNxW0cQkCj/VjBXm3KXF+P7PuvDqX5meDFhhmNHyXSNH13Omsm Y7Z9vU245dNGmfv3HvimxhoKnARE8v9DHMUi/FD8fYlZKCv7PtbjA06cuIuCJbJq4R3U 7MFCKIpSQ1Plto8Nb5GmpUEZPUKwiX07EE4Lyhjk7kGV0fYMrKUhmhhH/dFouCs0/USU CSuE5Pfx137Ly8NbbTwikMbCutA95a2gpZHhxTmjuUuBPSetUks89NNxAOPXWcfawsNJ xc+7nPxUEglsZ+K45jFxHn7F/TJzMMuLvlHcpTP0wG0L3K6C5dzSQbkUB9Qs3+fM/uUX WCdw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h189-20020a6383c6000000b0045feab44f0dsi17855pge.693.2022.10.13.11.07.55; Thu, 13 Oct 2022 11:08:08 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746596778094240121?= X-GMAIL-MSGID: =?utf-8?q?1746596778094240121?= 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)) {