Skip to contentSkip to conversation

fcntl: don't leak fd reference when fixup_compat_flock fails

PATCH New Jeff Layton 1 participant 1 message Nov 14, 2017

Subsystems (2)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

PATCH 1/1 fcntl: don't leak fd reference when fixup_compat_flock fails

From: Jeff Layton <[email protected]>

Currently we just return err here, but we need to put the fd reference first.

Fixes 94073ad77fff (fs/locks: don't mess with the address limit in compat_fcntl64)
---
 fs/fcntl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

I don't have a great way to test this. There's another similar bug in the F_GETLK64 case as well, but Vitaly is looking at another problem there.

fs/fcntl.c +2 -3
index e44a95dd3f86..0793eca4d0ec 100644
@@ -632,9 +632,8 @@ COMPAT_SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd,
 		if (err)
 			break;
 		err = fixup_compat_flock(&flock);
-		if (err)
-			return err;
-		err = put_compat_flock(&flock, compat_ptr(arg));
+		if (!err)
+			err = put_compat_flock(&flock, compat_ptr(arg));
 		break;
 	case F_GETLK64:
 	case F_OFD_GETLK:
Signature · 1 line
2.14.3