diff mbox series

[v2,2/2] ceph: fix caps reference leakage for fscrypt size truncating

Message ID 20220411001426.251679-3-xiubli@redhat.com (mailing list archive)
State New, archived
Headers show
Series ceph: misc fix size truncate for fscrypt | expand

Commit Message

Xiubo Li April 11, 2022, 12:14 a.m. UTC
From: Xiubo Li <xiubli@redhat.com>

Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
 fs/ceph/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Luis Henriques April 11, 2022, 4:30 p.m. UTC | #1
On Mon, Apr 11, 2022 at 08:14:26AM +0800, xiubli@redhat.com wrote:
> From: Xiubo Li <xiubli@redhat.com>
> 
> Signed-off-by: Xiubo Li <xiubli@redhat.com>
> ---
>  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 a2ff964e332b..6788a1f88eb6 100644
> --- a/fs/ceph/inode.c
> +++ b/fs/ceph/inode.c
> @@ -2301,7 +2301,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;
>  
> @@ -2365,6 +2364,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);
> -- 
> 2.27.0
> 

If the plan is to squash this into commit "ceph: add truncate size
handling support for fscrypt" it may be worth also fix the
kmap_local_page()/kunmap_local() as the first few 'goto out' jumps
shouldn't be doing the kunmap.

Cheers,
--
Luís
Xiubo Li April 12, 2022, 1:02 a.m. UTC | #2
On 4/12/22 12:30 AM, Luís Henriques wrote:
> On Mon, Apr 11, 2022 at 08:14:26AM +0800, xiubli@redhat.com wrote:
>> From: Xiubo Li <xiubli@redhat.com>
>>
>> Signed-off-by: Xiubo Li <xiubli@redhat.com>
>> ---
>>   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 a2ff964e332b..6788a1f88eb6 100644
>> --- a/fs/ceph/inode.c
>> +++ b/fs/ceph/inode.c
>> @@ -2301,7 +2301,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;
>>   
>> @@ -2365,6 +2364,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);
>> -- 
>> 2.27.0
>>
> If the plan is to squash this into commit "ceph: add truncate size
> handling support for fscrypt" it may be worth also fix the
> kmap_local_page()/kunmap_local() as the first few 'goto out' jumps
> shouldn't be doing the kunmap.

Good catch, will fix it in V3.

-- Xiubo


> Cheers,
> --
> Luís
>
diff mbox series

Patch

diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
index a2ff964e332b..6788a1f88eb6 100644
--- a/fs/ceph/inode.c
+++ b/fs/ceph/inode.c
@@ -2301,7 +2301,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;
 
@@ -2365,6 +2364,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);