From patchwork Mon Oct 24 11:29:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp418129wru; Mon, 24 Oct 2022 05:14:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM479BUbMzSQSWz2ry8YPaYR4xj9xxvRhNWUERuwjb7ENiLxPxO2sZou5QmMDpQSoDZmkqE9 X-Received: by 2002:a63:f056:0:b0:46e:99bb:166d with SMTP id s22-20020a63f056000000b0046e99bb166dmr18788706pgj.480.1666613649518; Mon, 24 Oct 2022 05:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613649; cv=none; d=google.com; s=arc-20160816; b=L/xnFEu3OINlsDTuEWobWNrPyjMCNfDI2F7KCBl3gMTvQOReqFdeuzYKCnjp2ow9n5 C4J2bf+mFmJhxgTJURQZbiX0YMONxK16df4GRj49MFP/2r6Pv2lYzDHwTRSYB19oDv16 G/pksk8AOQib4E32z91z/+myxN8Uy50U499U5jcUHZDZuKc/SciJOGLAEaE4mIRbp8a0 CbEjXKRUy9Ab2s31jZSY+BIcne93jqUy8dCm7Ta6dWWFCqEhk/5Y9w2kAFExOmBcCvd3 5DN8dRxwuUod1y3EIKteCsPiFw8r6euvc0foWuawWxBlbkEBQRtiFareFI633gCHReld EDxw== 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=YaNOmbuA2W/42y9DLb3m4ngj90Rey4ddTCF9+cXOp4U=; b=N4ShidntQL8SouP/qCbfZj0L3PGHtauPFMu6Z466MnjbWOK/FXIThb5X4/qfpiRIin wKA0fGF8DjG2VyOFAB8CpBN6MYmOFqMl2gDZOUYe5UH0EZhrfJdvMSfXQT0b1f7Rst99 Yv74vz2z8lR67UkiYl6m/H0SqaEEnxwN8C5sOrx5s/rrqA1JqLsBOTLEKG+3BgBB7fyX bzNq9znZDNNqG3ZIaoH+1qRzbYe7n9CwNKqYwyqeSREjT9W1OMcNe5Qi7Ll6cXzOug77 J5nCO1HQAlxR7mT8F9tvRChqHZACuOBpOyLQ57sl2KpUjZUPrvgKFk3IAbcsCHcW+Q27 uxcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="m7OQka/b"; 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 b6-20020a170903228600b0017f75ce8a2esi38313101plh.575.2022.10.24.05.13.54; Mon, 24 Oct 2022 05:14:09 -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="m7OQka/b"; 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 S232604AbiJXMFy (ORCPT + 99 others); Mon, 24 Oct 2022 08:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232608AbiJXMDz (ORCPT ); Mon, 24 Oct 2022 08:03:55 -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 5684D2F649; Mon, 24 Oct 2022 04:49:54 -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 23B20B811A6; Mon, 24 Oct 2022 11:48:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E5DBC433C1; Mon, 24 Oct 2022 11:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612101; bh=TMvR2MeejFZ+Q3PY0N79YCpGWHa+6Q5n9P36TzDFrTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m7OQka/bJGqW3Kqewqd8J/NvhTu2hASYZbIh+s7auPwHwxNMV88Asn4VUoSR9JKtH fCurSwy6tY72lQk0IcahVrRsz+PI7xyJLiR0NOwNfMPc7KyvkxSmfSmPObE4DAku7u YINyr4mO+7K4d+KhPPtbwNmsDRo8rwyvZxBsN8zA= 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.14 039/210] ceph: dont truncate file in atomic_open Date: Mon, 24 Oct 2022 13:29:16 +0200 Message-Id: <20221024112958.258391812@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747571074327477568?= X-GMAIL-MSGID: =?utf-8?q?1747571074327477568?= 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 @@ -381,6 +381,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) { err = ceph_pre_init_acls(dir, &mode, &acls); if (err < 0) @@ -411,9 +417,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;