[Devel] [PATCH RHEL8 COMMIT] ms/ovl: Fix dereferencing possible ERR_PTR()

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 16 13:47:54 MSK 2020


The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.3.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.11
------>
commit 0cefd3e4c22a2d7f64064ae7cde611fd0fe885e1
Author: Ding Xiang <dingxiang at cmss.chinamobile.com>
Date:   Mon Sep 9 16:29:56 2019 +0800

    ms/ovl: Fix dereferencing possible ERR_PTR()
    
    if ovl_encode_real_fh() fails, no memory was allocated
    and the error in the error-valued pointer should be returned.
    
    Fixes: 9b6faee07470 ("ovl: check ERR_PTR() return value from ovl_encode_fh()")
    Signed-off-by: Ding Xiang <dingxiang at cmss.chinamobile.com>
    Cc: <stable at vger.kernel.org> # v4.16+
    Signed-off-by: Miklos Szeredi <mszeredi at redhat.com>
    
    ===================================================
    https://bugzilla.redhat.com/show_bug.cgi?id=1843373
    
    Found by vvs@ using smatch on RHEL7.9 beta kernel:
    smatch: fs/overlayfs/export.c:249 ovl_d_to_fh() error: 'fh'
    dereferencing possible ERR_PTR()
    
    Fixed in mainline by:
    97f024b ovl: Fix dereferencing possible ERR_PTR()
    
    https://jira.sw.ru/browse/PSBM-104589
    
    (cherry picked from commit 97f024b9171e74c4443bbe8a8dce31b917f97ac5)
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 fs/overlayfs/export.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c
index 54e5d17d7f3e..6fe303850c9e 100644
--- a/fs/overlayfs/export.c
+++ b/fs/overlayfs/export.c
@@ -230,9 +230,8 @@ static int ovl_d_to_fh(struct dentry *dentry, char *buf, int buflen)
 	/* Encode an upper or lower file handle */
 	fh = ovl_encode_real_fh(enc_lower ? ovl_dentry_lower(dentry) :
 				ovl_dentry_upper(dentry), !enc_lower);
-	err = PTR_ERR(fh);
 	if (IS_ERR(fh))
-		goto fail;
+		return PTR_ERR(fh);
 
 	err = -EOVERFLOW;
 	if (fh->len > buflen)


More information about the Devel mailing list