lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8e7318d0-04a1-3a41-a660-066791a2f95d@auristor.com>
Date:   Wed, 28 Jun 2023 16:15:54 -0400
From:   Jeffrey E Altman <jaltman@...istor.com>
To:     David Howells <dhowells@...hat.com>,
        Marc Dionne <marc.dionne@...istor.com>
Cc:     linux-afs@...ts.infradead.org, linux-fsdevel@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] afs: Fix accidental truncation when storing data

On 6/28/2023 9:47 AM, David Howells wrote:
>      
> When an AFS FS.StoreData RPC call is made, amongst other things it is given
> the resultant file size to be.  On the server, this is processed by
> truncating the file to new size and then writing the data.
>
> Now, kafs has a lock (vnode->io_lock) that serves to serialise operations
> against a specific vnode (ie. inode), but the parameters for the op are set
> before the lock is taken.  This allows two writebacks (say sync and kswapd)
> to race - and if writes are ongoing the writeback for a later write could
> occur before the writeback for an earlier one if the latter gets
> interrupted.
>
> Note that afs_writepages() cannot take i_mutex and only takes a shared lock
> on vnode->validate_lock.
>
> Also note that the server does the truncation and the write inside a lock,
> so there's no problem at that end.
>
> Fix this by moving the calculation for the proposed new i_size inside the
> vnode->io_lock.  Also reset the iterator (which we might have read from)
> and update the mtime setting there.
>
> Fixes: bd80d8a80e12 ("afs: Use ITER_XARRAY for writing")
> Reported-by: Marc Dionne <marc.dionne@...istor.com>
> Signed-off-by: David Howells <dhowells@...hat.com>
> cc: linux-afs@...ts.infradead.org
> cc: linux-fsdevel@...r.kernel.org
> ---
>   fs/afs/write.c |    8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/fs/afs/write.c b/fs/afs/write.c
> index 8750b99c3f56..c1f4391ccd7c 100644
> --- a/fs/afs/write.c
> +++ b/fs/afs/write.c
> @@ -413,17 +413,19 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_t
>   	afs_op_set_vnode(op, 0, vnode);
>   	op->file[0].dv_delta = 1;
>   	op->file[0].modification = true;
> -	op->store.write_iter = iter;
>   	op->store.pos = pos;
>   	op->store.size = size;
> -	op->store.i_size = max(pos + size, vnode->netfs.remote_i_size);
>   	op->store.laundering = laundering;
> -	op->mtime = vnode->netfs.inode.i_mtime;
>   	op->flags |= AFS_OPERATION_UNINTR;
>   	op->ops = &afs_store_data_operation;
>   
>   try_next_key:
>   	afs_begin_vnode_operation(op);
> +
> +	op->store.write_iter = iter;
> +	op->store.i_size = max(pos + size, vnode->netfs.remote_i_size);
> +	op->mtime = vnode->netfs.inode.i_mtime;
> +
>   	afs_wait_for_operation(op);
>   
>   	switch (op->error) {

Reviewed-by: Jeffrey Altman <jaltman@...istor.com>



Download attachment "smime.p7s" of type "application/pkcs7-signature" (4039 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ