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

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


The commit is pushed to "branch-rh7-3.10.0-1127.10.1.vz7.162.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.10.1.vz7.162.3
------>
commit 0fe2adea81ea2f2835abd51bab7616eb52236f97
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()
    
    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 9a5ccbb08bf38..03acd05ba6427 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