Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5172imu; Sun, 4 Nov 2018 17:33:21 -0800 (PST) X-Google-Smtp-Source: AJdET5d5ZkhD0VOAsnp3D9VX9i1aLaGLUf4wDroK+gefFpZy3mq0ZVafzuPJc0p8HOgTaG7+q+4J X-Received: by 2002:a62:2a04:: with SMTP id q4-v6mr19985827pfq.61.1541381601356; Sun, 04 Nov 2018 17:33:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541381601; cv=none; d=google.com; s=arc-20160816; b=X2KXW5UKw7eN2zmdy33/gAsiZDbY0xae4F77+cuJhsjWuAnUICYwTULa0VXTYiNqxr mn26biZ4KWj3jAqXLpOW5Dw2HTcgYla+DrVgRch4ftGYDNHkDN19qbcbLyDIF+MGEUi4 q5or++5Tst606iaWk93kZ2ZaX4SPLiuxaNfuPwz0n4bAzDskjKN8iy3cPArLXNACowlW zkL53RZWmn6LRH2j78dOOONbqc4n+z2s/63/jl1YjP/Pcw/GPiP+9591j9apHRbgfkBq vCKQ9MNKpXKnoagvRdck0Fb6mTOejN3SRy+BHizB03mVs2pbg4NIQOltW5cd4vSmXiXm wPCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from; bh=WV0ac0cz4Ed0OiHOJb6ZE3f+l2q3Ccq6jUQB7HFcrAs=; b=Ie8nZbj3e+QS5yPL53qZArzSg8ClZHTgXi8CcpXtyZkZavb5GNQINTdowcEjlduWMl OSFD0eqI/VxNr68AkiZNqa5jpYHPs7hN+0hEYgSrnWTGd87h8GN6xQP1J6ZGr64+VesA D0yh/VF36sHSKKtkJuiy8Cj0ZANWm9oWUjsrNjz8DR+/T8HAB55qhhXTAXfRAl6/Q5Tu UuBReo+YiArExm+0dC8WWVZLh6sWa4Zd5RW7JJXGO5V5anHXnXawCVNfKmO5rYa53cy8 dIdtVFa+c3DKYpfCtzzDlR33BakfUc2bGKpwgqUG1v+7YJE2qcJenZByYBxWZKA25dtM 6y1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e92-v6si41942261pld.45.2018.11.04.17.33.06; Sun, 04 Nov 2018 17:33:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728381AbeKEKtZ (ORCPT + 99 others); Mon, 5 Nov 2018 05:49:25 -0500 Received: from mx2.suse.de ([195.135.220.15]:60684 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726494AbeKEKtY (ORCPT ); Mon, 5 Nov 2018 05:49:24 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 81970AFD9; Mon, 5 Nov 2018 01:32:16 +0000 (UTC) From: NeilBrown To: Jeff Layton , Alexander Viro Date: Mon, 05 Nov 2018 12:30:47 +1100 Subject: [PATCH 06/12] locks: use properly initialized file_lock when unlocking. Cc: "J. Bruce Fields" , Martin Wilck , linux-fsdevel@vger.kernel.org, Frank Filz , linux-kernel@vger.kernel.org Message-ID: <154138144784.31651.8715342652118090206.stgit@noble> In-Reply-To: <154138128401.31651.1381177427603557514.stgit@noble> References: <154138128401.31651.1381177427603557514.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both locks_remove_posix() and locks_remove_flock() use a struct file_lock without calling locks_init_lock() on it. This means the various list_heads are not initialized, which will become a problem with a later patch. So change them both to initialize properly. For flock locks, this involves using flock_make_lock(), and changing it to allow a file_lock to be passed in, so memory allocation isn't always needed. Signed-off-by: NeilBrown --- fs/locks.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index b8f33792a0a6..ea999ce0e93c 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -418,15 +418,15 @@ static inline int flock_translate_cmd(int cmd) { /* Fill in a file_lock structure with an appropriate FLOCK lock. */ static struct file_lock * -flock_make_lock(struct file *filp, unsigned int cmd) +flock_make_lock(struct file *filp, unsigned int cmd, struct file_lock *fl) { - struct file_lock *fl; int type = flock_translate_cmd(cmd); if (type < 0) return ERR_PTR(type); - fl = locks_alloc_lock(); + if (fl == NULL) + fl = locks_alloc_lock(); if (fl == NULL) return ERR_PTR(-ENOMEM); @@ -2008,7 +2008,7 @@ SYSCALL_DEFINE2(flock, unsigned int, fd, unsigned int, cmd) !(f.file->f_mode & (FMODE_READ|FMODE_WRITE))) goto out_putf; - lock = flock_make_lock(f.file, cmd); + lock = flock_make_lock(f.file, cmd, NULL); if (IS_ERR(lock)) { error = PTR_ERR(lock); goto out_putf; @@ -2483,6 +2483,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) if (!ctx || list_empty(&ctx->flc_posix)) return; + locks_init_lock(&lock); lock.fl_type = F_UNLCK; lock.fl_flags = FL_POSIX | FL_CLOSE; lock.fl_start = 0; @@ -2506,19 +2507,15 @@ EXPORT_SYMBOL(locks_remove_posix); static void locks_remove_flock(struct file *filp, struct file_lock_context *flctx) { - struct file_lock fl = { - .fl_owner = filp, - .fl_pid = current->tgid, - .fl_file = filp, - .fl_flags = FL_FLOCK | FL_CLOSE, - .fl_type = F_UNLCK, - .fl_end = OFFSET_MAX, - }; + struct file_lock fl; struct inode *inode = locks_inode(filp); if (list_empty(&flctx->flc_flock)) return; + flock_make_lock(filp, LOCK_UN, &fl); + fl.fl_flags |= FL_CLOSE; + if (filp->f_op->flock) filp->f_op->flock(filp, F_SETLKW, &fl); else