Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1355002rwi; Thu, 13 Oct 2022 12:28:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5DF85/APZn/oHWAEN6v2wu2c5p1nm35+WcbRd/+SdgM3B0mMzraHIVnwElfrLciMUYnAuw X-Received: by 2002:a17:902:ef85:b0:17f:5f55:9425 with SMTP id iz5-20020a170902ef8500b0017f5f559425mr1257768plb.135.1665689292759; Thu, 13 Oct 2022 12:28:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665689292; cv=none; d=google.com; s=arc-20160816; b=ZuXBdzZAE9yYxu2rRCSNkFqCJSDMF1dvMY5fqqHQ6rHqhw7F0LXvxxhQDI/Q2qzTsC oIdC97HzI9rSDARPQg3kdulMH2kRJOroGseulgI3EOkQLWL3EyP8M0plB2t6Zf+B1Pfi oZGXdW8Aj2x30myrjZMamfp3q8yP/j513KRl13mBQOZPJSZf2dPY5Ahjg0jCVE/8Xo6r vmst60e8EsK7tH4SRnt3BxizfJkqxNkbsBJfh0ZHVxIGHFhHumOk5XCkt1kgmWDw3dXr 3Ir9a4IkojSguSKCFm1lvjMJv1/F06s3/LeOflOEQgndD5xiD55T2ES6b/UVfqgnZcqY frGg== 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=tHNV1CGMwjc78kK1rq6JYDJsCpX3avhcELDKZew+gfQ=; b=ljohdr7RckSCQv7XHeBjz9cbfy79dtjTKD1EVjKAHSkNGnMZCCISChACIbqnjYCPrQ oPe4N6HZUEi6mYbY6IHue2jXR3heXqAiSTCTeOoVT+7AxzxTBIgzICydbt3bAapUA+W8 zsnDSdWcnRB5v25u3kf8279cust3WvG+yjbXpNfc/ExuttAs4EcJyn3uomTRu9tSEnht hsvxTqEWVos3mO3QOvydC++Fh6hCxFG2CXsczfppLk98cxhNnB4P8Xy9RwJIXZvUvxJ8 04KyXQJLKUUqOb4KI06TrbZq2bZbKkaKyBfnKLjwjQ5fTgnV7ESfbnYCNyE0LA7zsaxj bZqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vAexPPVY; 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 b20-20020a170902b61400b0017a0e8713cesi466275pls.452.2022.10.13.12.28.00; Thu, 13 Oct 2022 12:28:12 -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=vAexPPVY; 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 S231178AbiJMSL6 (ORCPT + 99 others); Thu, 13 Oct 2022 14:11:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbiJMSKx (ORCPT ); Thu, 13 Oct 2022 14:10:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2CE6175786; Thu, 13 Oct 2022 11:08:02 -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 dfw.source.kernel.org (Postfix) with ESMTPS id BE4B361909; Thu, 13 Oct 2022 17:54:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1730C433D6; Thu, 13 Oct 2022 17:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683690; bh=0WzNF0L24PGQtCOE+y+KzS6zPy33CwgpeY8JqNIhV9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vAexPPVYRLi9VpzbOqFMXyX6SlI9iuzhcUrXN06KSFKZjN7DJS6FsQsYXU5xqTKna +PGfuyKKQ4ZD1OxQgBwhHeHX2qpwX9HUBoYVlFosh7tvg0V7TeFlkbXhJPWqbvGwud WbPga4MBGDCtywdyzLYeYtyNV5GeghlcCtDc10kI= 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.10 05/54] ceph: dont truncate file in atomic_open Date: Thu, 13 Oct 2022 19:51:59 +0200 Message-Id: <20221013175147.479149277@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175147.337501757@linuxfoundation.org> References: <20221013175147.337501757@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.10 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; @@ -769,9 +775,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); err = ceph_handle_snapdir(req, dentry, err); if (err) goto out_req;