[Devel] [PATCH RHEL8 COMMIT] ms/nfsd: memory corruption in nfsd4_lock()

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 2 19:48:04 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit af5cd352f307f290137b450b0a1b32b9c8c30412
Author: Vasily Averin <vvs at virtuozzo.com>
Date:   Wed Jun 2 19:48:04 2021 +0300

    ms/nfsd: memory corruption in nfsd4_lock()
    
    New struct nfsd4_blocked_lock allocated in find_or_allocate_block()
    does not initialized nbl_list and nbl_lru.
    If conflock allocation fails rollback can call list_del_init()
    access uninitialized fields and corrupt memory.
    
    v2: just initialize nbl_list and nbl_lru right after nbl allocation.
    
    Fixes: 76d348fadff5 ("nfsd: have nfsd4_lock use blocking locks for v4.1+ lock")
    Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
    
    Reviewed-by: Jeff Layton <jlayton at kernel.org>
    Signed-off-by: Chuck Lever <chuck.lever at oracle.com>
    
    https://jira.sw.ru/browse/PSBM-102407
    
    (cherry picked from ms commit e1e8399eee72 ("nfsd: memory corruption in
    nfsd4_lock()"))
    
    taken from vz7 commit b401296638c3 ("ms/nfsd: memory corruption in
    nfsd4_lock()")
    
    Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 fs/nfsd/nfs4state.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 364025df922b..fc664f059efe 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -265,6 +265,8 @@ find_or_allocate_block(struct nfs4_lockowner *lo, struct knfsd_fh *fh,
 	if (!nbl) {
 		nbl= kmalloc(sizeof(*nbl), GFP_KERNEL);
 		if (nbl) {
+			INIT_LIST_HEAD(&nbl->nbl_list);
+			INIT_LIST_HEAD(&nbl->nbl_lru);
 			fh_copy_shallow(&nbl->nbl_fh, fh);
 			locks_init_lock(&nbl->nbl_lock);
 			nfsd4_init_cb(&nbl->nbl_cb, lo->lo_owner.so_client,


More information about the Devel mailing list