Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6856851rwi; Mon, 24 Oct 2022 07:00:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM65D+nASzzdkaKRplwtkJXqSVkMK8/qopJ9MuHYNuXZ1jUie92mPkK6mqooiy3CrlTVD1ZW X-Received: by 2002:a17:90a:2e89:b0:212:ea82:bbb with SMTP id r9-20020a17090a2e8900b00212ea820bbbmr13133979pjd.171.1666620004796; Mon, 24 Oct 2022 07:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666620004; cv=none; d=google.com; s=arc-20160816; b=UIAQF6tTJ2DI9DE0voQz/ggdgO40KxsKTzdNNY0rbE6sWyjiP+S0DBlqdWSVi2Fv/L m5AZRmMzAqlOaXGnez/dlNB6TT2wz/CKpMR6gEOdZgowTevF3OlVUIQJ3QYeWMWc4aKV d8AduSsvlgNRVEt0760dMOb4GgRHehsYVHszJzJRguycnezP90Lh6i5Xjx9zNS63kfml h4OGSK/DOdtVSwVQjQAQO5yCQTty5dYqRCVgOGiY0V39K5xJILTwOv0PxbKJYSsWMJzS TiYegbR9efKvSRkuA8iAWJFgaeNa2UImRXNxuGR5Fv/UjdNy7bj7fxzkuNsmeNen/5Sm ACOQ== 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=JsgkDUA1EV3JxPLkguaDFJmRlht2o2HwjqJcgXNpNpc=; b=aYf5E58FGsf02Hm5XToS02k9LZKVT4sriGROYspgrebhfdiuVsa7Zr4Al/43CKfDSQ bRzSpGQCfsaWfSscqxaPPRdbNlaWav75HHyndGGyLiRqn3WZynDIYwn37kjKzwAS1MWd I+vo21tk+/vCwh59SdmC2JARIT9I7FO1XnnEKQQbMNL13qFg5xYtLnUpOOu/aykasS1j e6o5kDcAOFHt2D1dUbH/hv9fsUNGZdG56oiecY9Zizrz/apZP6I3WgjdF5VS+gKXfu+x wX1QNMDkuMZ9/sWWGeHvfv2mDGcCCnJOHM5w/BCdKR/pmRZguHrO6vopv41mHfBt2mdV d6mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=urhT5Zua; 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 x10-20020a170902ec8a00b0016f5e7d0febsi40964486plg.244.2022.10.24.06.59.53; Mon, 24 Oct 2022 07:00:04 -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=urhT5Zua; 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 S234198AbiJXMni (ORCPT + 99 others); Mon, 24 Oct 2022 08:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234081AbiJXMlz (ORCPT ); Mon, 24 Oct 2022 08:41:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 720C28A7FB; Mon, 24 Oct 2022 05:08:34 -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 B0581612B9; Mon, 24 Oct 2022 11:56:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C03D2C433D6; Mon, 24 Oct 2022 11:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612609; bh=2Q21U+OZtgQgt7+d3W97F/pzkhbw11NkEC8p2AfJ2q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=urhT5ZuajtL4XZ+Y1udKcnzab0aupcjTfsS6nF4Pp4F923OghplBappwQTQWHI0Fl om6tsh963BgZ9juqga7Q9Hg3gFSoI6rzFB38SBhRG9kJsm7iEcyQJ2BED8/hSmSDms 0BI1/8FNIpzfzaZopawAjIRFZCSZfwoTL6g/av3w= 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.19 021/229] ceph: dont truncate file in atomic_open Date: Mon, 24 Oct 2022 13:29:00 +0200 Message-Id: <20221024112959.826609588@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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 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 @@ -446,6 +446,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; @@ -478,9 +484,7 @@ int ceph_atomic_open(struct inode *dir, req->r_parent = dir; 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;