From patchwork Tue Apr 12 07:07:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 560066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E17AC433F5 for ; Tue, 12 Apr 2022 09:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351684AbiDLJwo (ORCPT ); Tue, 12 Apr 2022 05:52:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351230AbiDLH2A (ORCPT ); Tue, 12 Apr 2022 03:28:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 797C94EF5F for ; Tue, 12 Apr 2022 00:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649747279; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IRF6LVwJSHJOWFm7I1F+YrA+lOMpLLhwycut1OVWExo=; b=eAFR3iuBPcRl+TmQ/4lSNwjhh/25VexeKDNpe3teqaTeboqHIDZ4ZqnsQ4VQ5AqJSjwOzo 0IgyHTBYJQZD0ohSV6gu7emg6bahGRZXzkHNKJBmwCP5RNy77Utn3gHzGB2/Dw6U+HIUph Re4/l1Da0Tq9/d4kYoKwH9BeSpEIQX4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-460-ZDLDB1h0PJa-m8ZfoBguNg-1; Tue, 12 Apr 2022 03:07:55 -0400 X-MC-Unique: ZDLDB1h0PJa-m8ZfoBguNg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 45451185A7B2; Tue, 12 Apr 2022 07:07:55 +0000 (UTC) Received: from localhost (unknown [10.72.47.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FDE140CF91A; Tue, 12 Apr 2022 07:07:54 +0000 (UTC) From: Xiubo Li To: jlayton@kernel.org Cc: idryomov@gmail.com, vshankar@redhat.com, lhenriques@suse.de, ceph-devel@vger.kernel.org, Xiubo Li Subject: [PATCH v3 1/3] ceph: flush small range instead of the whole map for truncate Date: Tue, 12 Apr 2022 15:07:43 +0800 Message-Id: <20220412070745.22795-2-xiubli@redhat.com> In-Reply-To: <20220412070745.22795-1-xiubli@redhat.com> References: <20220412070745.22795-1-xiubli@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Signed-off-by: Xiubo Li --- fs/ceph/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index fa0d3018d981..a5145a2b7228 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2274,8 +2274,13 @@ static int fill_fscrypt_truncate(struct inode *inode, ceph_cap_string(issued)); /* Try to writeback the dirty pagecaches */ - if (issued & (CEPH_CAP_FILE_BUFFER)) - filemap_write_and_wait(inode->i_mapping); + if (issued & (CEPH_CAP_FILE_BUFFER)) { + loff_t lend = orig_pos + CEPH_FSCRYPT_BLOCK_SHIFT - 1; + ret = filemap_write_and_wait_range(inode->i_mapping, + orig_pos, lend); + if (ret < 0) + goto out; + } page = __page_cache_alloc(GFP_KERNEL); if (page == NULL) { From patchwork Tue Apr 12 07:07:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 561234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A28C9C433FE for ; Tue, 12 Apr 2022 09:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229464AbiDLJvz (ORCPT ); Tue, 12 Apr 2022 05:51:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351968AbiDLH2O (ORCPT ); Tue, 12 Apr 2022 03:28:14 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C00E4F444 for ; Tue, 12 Apr 2022 00:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649747284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O0fP0oHi8cKZCOC9vXmnlFkANQVwtuXoa0AwfAmlD6o=; b=eQibg9SDzRJ0HpInQRVjnt6qatZg9Yd0pfmkTSzWQrMg6t6KAKGOpZqc9lbINQhnx9rzNC Y61UmpGgWaVjOMOEQjwJkb69RvP1m10wxXUT1M9l05wnD9SWKRx2rsyiLphxCxzJWDBf4U CCKKsoz/zNFs40+mpPRlaVDygnCkZco= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-42-TucoJEAgMtyv7PQxfpF_gw-1; Tue, 12 Apr 2022 03:07:58 -0400 X-MC-Unique: TucoJEAgMtyv7PQxfpF_gw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6251380346E; Tue, 12 Apr 2022 07:07:58 +0000 (UTC) Received: from localhost (unknown [10.72.47.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D49540F4940; Tue, 12 Apr 2022 07:07:56 +0000 (UTC) From: Xiubo Li To: jlayton@kernel.org Cc: idryomov@gmail.com, vshankar@redhat.com, lhenriques@suse.de, ceph-devel@vger.kernel.org, Xiubo Li Subject: [PATCH v3 2/3] ceph: fix caps reference leakage for fscrypt size truncating Date: Tue, 12 Apr 2022 15:07:44 +0800 Message-Id: <20220412070745.22795-3-xiubli@redhat.com> In-Reply-To: <20220412070745.22795-1-xiubli@redhat.com> References: <20220412070745.22795-1-xiubli@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Signed-off-by: Xiubo Li --- fs/ceph/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index a5145a2b7228..1c775a365b5e 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2300,7 +2300,6 @@ static int fill_fscrypt_truncate(struct inode *inode, pos = orig_pos; ret = __ceph_sync_read(inode, &pos, &iter, &retry_op, &objver); - ceph_put_cap_refs(ci, got); if (ret < 0) goto out; @@ -2364,6 +2363,7 @@ static int fill_fscrypt_truncate(struct inode *inode, out: dout("%s %p size dropping cap refs on %s\n", __func__, inode, ceph_cap_string(got)); + ceph_put_cap_refs(ci, got); kunmap_local(iov.iov_base); if (page) __free_pages(page, 0); From patchwork Tue Apr 12 07:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 560068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20EF7C433F5 for ; Tue, 12 Apr 2022 09:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244231AbiDLJvk (ORCPT ); Tue, 12 Apr 2022 05:51:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351710AbiDLH2N (ORCPT ); Tue, 12 Apr 2022 03:28:13 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 54B6D4F442 for ; Tue, 12 Apr 2022 00:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649747283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i7nGVtq761THI2iJueCqXEBM16T97URAaXffhqMv7mA=; b=Q1PopZ3ZN6W2jpNtDeEeA4asiBH0TTksfHTNKXiJOj61CynbfwNEG23bc96sg3vx+RN5LU ZK/MrI7KZFdpO+hEF1B8qB6xh+REKwqBIth7nLaHtdyARJoyCsiOf91LHsaB8DgsF6ucW2 24DVcL8ANQRBJ9oP9IvQ5MsUCD2Lzec= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-wuCTeVNJMf2_K9vsA-szow-1; Tue, 12 Apr 2022 03:08:01 -0400 X-MC-Unique: wuCTeVNJMf2_K9vsA-szow-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3457238025E9; Tue, 12 Apr 2022 07:08:01 +0000 (UTC) Received: from localhost (unknown [10.72.47.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D05D200B66F; Tue, 12 Apr 2022 07:08:00 +0000 (UTC) From: Xiubo Li To: jlayton@kernel.org Cc: idryomov@gmail.com, vshankar@redhat.com, lhenriques@suse.de, ceph-devel@vger.kernel.org, Xiubo Li Subject: [PATCH v3 3/3] ceph: fix possible kunmaping random vaddr Date: Tue, 12 Apr 2022 15:07:45 +0800 Message-Id: <20220412070745.22795-4-xiubli@redhat.com> In-Reply-To: <20220412070745.22795-1-xiubli@redhat.com> References: <20220412070745.22795-1-xiubli@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Signed-off-by: Xiubo Li --- fs/ceph/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 1c775a365b5e..83f18b058d8c 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2253,7 +2253,7 @@ static int fill_fscrypt_truncate(struct inode *inode, loff_t pos, orig_pos = round_down(attr->ia_size, CEPH_FSCRYPT_BLOCK_SIZE); u64 block = orig_pos >> CEPH_FSCRYPT_BLOCK_SHIFT; struct ceph_pagelist *pagelist = NULL; - struct kvec iov; + struct kvec iov = {0}; struct iov_iter iter; struct page *page = NULL; struct ceph_fscrypt_truncate_size_header header; @@ -2364,7 +2364,8 @@ static int fill_fscrypt_truncate(struct inode *inode, dout("%s %p size dropping cap refs on %s\n", __func__, inode, ceph_cap_string(got)); ceph_put_cap_refs(ci, got); - kunmap_local(iov.iov_base); + if (iov.iov_base) + kunmap_local(iov.iov_base); if (page) __free_pages(page, 0); if (ret && pagelist)