From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <linux-kernel-owner@vger.kernel.org>
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1756388AbdKNUYh (ORCPT <rfc822;w@1wt.eu>);
        Tue, 14 Nov 2017 15:24:37 -0500
Received: from mail.kernel.org ([198.145.29.99]:51444 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1755432AbdKNUYe (ORCPT <rfc822;linux-kernel@vger.kernel.org>);
        Tue, 14 Nov 2017 15:24:34 -0500
DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5466C204EE
Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org
Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jlayton@kernel.org
From: Jeff Layton <jlayton@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Vitaly Lipatov <lav@etersoft.ru>, hch@lst.de, bfields@fieldses.org,
        Alexander Viro <viro@zeniv.linux.org.uk>, linux-kernel@vger.kernel.org
Subject: [PATCH] fcntl: don't leak fd reference when fixup_compat_flock fails
Date: Tue, 14 Nov 2017 15:24:31 -0500
Message-Id: <20171114202431.16632-1-jlayton@kernel.org>
X-Mailer: git-send-email 2.14.3
Sender: linux-kernel-owner@vger.kernel.org
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

From: Jeff Layton <jlayton@redhat.com>

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)
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 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.

diff --git a/fs/fcntl.c b/fs/fcntl.c
index e44a95dd3f86..0793eca4d0ec 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -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:
-- 
2.14.3

