From patchwork Mon Oct 24 11:29:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp433547wru; Mon, 24 Oct 2022 05:49:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45nAp1UwsHvLIWGl9KSVejsDXGUfIuKE4CxZtziDOWG4v35k11ksdhSlTso4PU/xqKGwO+ X-Received: by 2002:a17:902:e804:b0:186:5736:2b70 with SMTP id u4-20020a170902e80400b0018657362b70mr27420948plg.127.1666615792858; Mon, 24 Oct 2022 05:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615792; cv=none; d=google.com; s=arc-20160816; b=j3+xHrXyTXMp2grGy3JgNrFwWoaLap6vQD9oN9QfjOImG/VEBB2ir0ojS9M7PKbcAq ZisJMOly5begWr/hFKCvGbg5LJYv/phoCdeiQ0cIdKuYufGcBwdVTBx5ng4OjTHVnLga xK/WP/qUchbFFAI4+wjMvA+IXmt+KyaIJ4abRbqleLMbWkcPr0/VVTOa6P7xKGCOYVo4 1qt2PoT9ZLFIqCf8jH16H4MR0UX7JE3x+1Mf5+SRqUElpndFoawwRxzbbzFUvaR0B0de l78NwPy3Ai4KFWJFKtwzhU6kuNhet0qkmE2pidhgYuSOv9a3gQc+C88kTG7eNGk0tmrs dwjA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m6-20020a17090b068600b00212fd5f1ad5si5014021pjz.160.2022.10.24.05.49.39; Mon, 24 Oct 2022 05:49:52 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747573321511967942?= X-GMAIL-MSGID: =?utf-8?q?1747573321511967942?= 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;