Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5061752pxb; Thu, 14 Oct 2021 18:20:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTI19pOa4fhDmqrxpRIBF+ueuYSLYBN6R+u4evQ+ONAY2qvEgHWU+Pg6X2ABwV+lbnR0y9 X-Received: by 2002:a62:6d07:0:b0:446:c141:7d2d with SMTP id i7-20020a626d07000000b00446c1417d2dmr8754088pfc.28.1634260818192; Thu, 14 Oct 2021 18:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634260818; cv=none; d=google.com; s=arc-20160816; b=e6oeOxqJ9pRtKGMGwc87gEWMmrA2qhdJ/iSkZH1zQUqUAZP7fPeLs9PVh0WGJQJ+Jy fFTootuoDyvUqjooYzr2vD06Clpk2jW6bvg6+9fvFnXOV6UrRuJpo6gYGjgG58tFQn92 DXfSAUEsRa8GogWQ9moGZEQERosymdFqoN5bLMnRK9wctWroMakyEppOd/eZVgYnxti6 yOv7DK38UU9Fi1Zf/1Oq92PTSXE0qXvKnqbcdyXxWYKmNXzpiOpY3ORxbe5G5ca1rgtG 52naLMgSTEoPVxZnTxciXdXeSNyCp3cBS/bbS0UuDB0K+BBb61e4SfIcI7H/JywynsS6 7fwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gXL/osngchA2FDgU8XTMVRd79ymTelXRGtFELS9XZ+A=; b=NqU2xAzpklVjNv6e5eHY65hxw/2t8qHH89eLBl/ok3Gkj/j83yIkPN8opa3HYSQIha B8rlTu8Un31ksTlrF0AEglsN7ucyDqnzdbDkiciRkW3d1SQY7xbMA1Syrtaf6vUpV050 LhXqU2837XXZi53gXf7DWpxzMtlSYv56oD7uE6qGKgRfDUQUpoACMA8JpoLpDTYZOMrd p6/073Ars6iyKHkX6FZ3mB0jubkaqB5zKMrPPZt4fLws+BYT8pYhkPuj6WjP3LMmf4mg Zfs+Lt7+3oGz0J9F1xRiwnIru0I71lypk2lYMy81Zs7OvRX3WzAcaUK3mvzNxJZcs8nF 70bA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e13si7374572plh.209.2021.10.14.18.20.05; Thu, 14 Oct 2021 18:20:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233918AbhJNVlV (ORCPT + 99 others); Thu, 14 Oct 2021 17:41:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231596AbhJNVlV (ORCPT ); Thu, 14 Oct 2021 17:41:21 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0B44C061570; Thu, 14 Oct 2021 14:39:15 -0700 (PDT) Received: from localhost (unknown [IPv6:2804:14c:124:8a08::1007]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 537351F44F8C; Thu, 14 Oct 2021 22:39:14 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, repnop@google.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v7 19/28] fanotify: Limit number of marks with FAN_FS_ERROR per group Date: Thu, 14 Oct 2021 18:36:37 -0300 Message-Id: <20211014213646.1139469-20-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014213646.1139469-1-krisman@collabora.com> References: <20211014213646.1139469-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Since FAN_FS_ERROR memory must be pre-allocated, limit a single group from watching too many file systems at once. The current scheme guarantees 1 slot per filesystem, so limit the number of marks with FAN_FS_ERROR per group. Signed-off-by: Gabriel Krisman Bertazi --- fs/notify/fanotify/fanotify_user.c | 10 ++++++++++ include/linux/fsnotify_backend.h | 1 + 2 files changed, 11 insertions(+) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index f1cf863d6f9f..5324890500fc 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -959,6 +959,10 @@ static int fanotify_remove_mark(struct fsnotify_group *group, removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags, umask, &destroy_mark); + + if (removed & FAN_FS_ERROR) + group->fanotify_data.error_event_marks--; + if (removed & fsnotify_conn_mask(fsn_mark->connector)) fsnotify_recalc_mask(fsn_mark->connector); if (destroy_mark) @@ -1057,6 +1061,9 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, static int fanotify_group_init_error_pool(struct fsnotify_group *group) { + if (group->fanotify_data.error_event_marks >= FANOTIFY_DEFAULT_FEE_POOL) + return -ENOMEM; + if (mempool_initialized(&group->fanotify_data.error_events_pool)) return 0; @@ -1098,6 +1105,9 @@ static int fanotify_add_mark(struct fsnotify_group *group, if (added & ~fsnotify_conn_mask(fsn_mark->connector)) fsnotify_recalc_mask(fsn_mark->connector); + if (!(flags & FAN_MARK_IGNORED_MASK) && (mask & FAN_FS_ERROR)) + group->fanotify_data.error_event_marks++; + out: mutex_unlock(&group->mark_mutex); diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 9941c06b8c8a..96e1d31394ce 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -247,6 +247,7 @@ struct fsnotify_group { int f_flags; /* event_f_flags from fanotify_init() */ struct ucounts *ucounts; mempool_t error_events_pool; + unsigned int error_event_marks; } fanotify_data; #endif /* CONFIG_FANOTIFY */ }; -- 2.33.0