Received: by 10.223.185.116 with SMTP id b49csp1085933wrg; Fri, 23 Feb 2018 11:40:26 -0800 (PST) X-Google-Smtp-Source: AH8x226LrimKWftqdxkYlbDAgNMM5dKnPP4cThqrTM1CFqpvHYw/9PTQrosBLTe2wv+kglANAmog X-Received: by 10.98.48.2 with SMTP id w2mr2788285pfw.162.1519414825916; Fri, 23 Feb 2018 11:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519414825; cv=none; d=google.com; s=arc-20160816; b=daRAmcSrtYMoqrqnqv+IUzzU/I9Gjkcby2zWUKVmoZcw0o7rdMZ0JZ+/xPV2Tm56Da l0rCH+QvG+RmzQD2u25XepzZrNKOLvOv7Sm+2LCsFty6Zj9I5enfVZSdSLxA9VfrZjMg 5wHAN2tJuwKZz1sXbggrfoLWX2UZ3o5E3EtGlh4PqOgDikrZxFREK5bNS82RU5WjXcsV XAlGXv+Yy1cnoy8eybvhoNyYgPQcVeff32xQ223BQRT4+XT2hZbVAHaF+Z7xn9WQJGfk n6wzbGXNBtcZ8ZkwNlmDX9Q0fgt7J7kflum2c5zZNv3iZtiwboEOBoh+SoGHL2TrARKG NNJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rQDKzcZHB5Oymhh9fwQpKYlLYAPo3oc5WtZpnUM+0qw=; b=t6FlVZ6miC2pKjg5Uts4zEPHuYQzGXYmLUep2b3Klzom1G7EHkzjUgdqSMTvLbFLCx AjW+/nWwrIEwnoOHSF0L23Qj33HMSqC5y8pg7JIwZmCaFWdqXJGvvUFiGnueKHZRJRE1 BVBSkKOHWl5qRIGBIJ+0x8/pzNIKKFeGhNfXnYA/ZFraHIzZe5NIFicuGQdLWfMGJOtL GYIj+B0TVK5+ngzxmdLcSoihedCF5qlo+LVbEQ/uUyOf6A2taSDZOc7+s2+6bEHCo1Po ARk0VWvHVUXQZvwc2nA7vTYmb3P4K6LTsk2e6ypJPmsYmnh+jJ74WOT4a8CcNVUhD0wi uKaQ== 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 c1si1881650pgq.109.2018.02.23.11.40.11; Fri, 23 Feb 2018 11:40:25 -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 S934614AbeBWStw (ORCPT + 99 others); Fri, 23 Feb 2018 13:49:52 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45440 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934134AbeBWStt (ORCPT ); Fri, 23 Feb 2018 13:49:49 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9261911B5; Fri, 23 Feb 2018 18:49:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Amir Goldstein , Jan Kara Subject: [PATCH 4.14 019/159] dnotify: Handle errors from fsnotify_add_mark_locked() in fcntl_dirnotify() Date: Fri, 23 Feb 2018 19:25:27 +0100 Message-Id: <20180223170745.516049276@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit b3a0066005821acdc0cdb092cb72587182ab583f upstream. fsnotify_add_mark_locked() can fail but we do not check its return value. This didn't matter before commit 9dd813c15b2c "fsnotify: Move mark list head from object into dedicated structure" as none of possible failures could happen for dnotify but after that commit -ENOMEM can be returned. Handle this error properly in fcntl_dirnotify() as otherwise we just hit BUG_ON(dn_mark->dn) in dnotify_free_mark(). Reviewed-by: Amir Goldstein Reported-by: syzkaller Fixes: 9dd813c15b2c101168808d4f5941a29985758973 Signed-off-by: Jan Kara Signed-off-by: Greg Kroah-Hartman --- fs/notify/dnotify/dnotify.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -319,7 +319,11 @@ int fcntl_dirnotify(int fd, struct file dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark); spin_lock(&fsn_mark->lock); } else { - fsnotify_add_mark_locked(new_fsn_mark, inode, NULL, 0); + error = fsnotify_add_mark_locked(new_fsn_mark, inode, NULL, 0); + if (error) { + mutex_unlock(&dnotify_group->mark_mutex); + goto out_err; + } spin_lock(&new_fsn_mark->lock); fsn_mark = new_fsn_mark; dn_mark = new_dn_mark; @@ -345,6 +349,7 @@ int fcntl_dirnotify(int fd, struct file */ if (dn_mark == new_dn_mark) destroy = 1; + error = 0; goto out; }