From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D4763B0AF8; Mon, 30 Mar 2026 09:14:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774862062; cv=none; b=O11NEJkPMh9H4OxLVgaDip6rnDVxZOUNlBUQ+sqt1hueIpTelTB982CU7rMlyg7gpX8CaK/55MHhzko6y5LwU4BUkBD6oR9bzSTAzQ7kN4JJPUseMsirgHCvfWexIsUyQIrFK/MztCz0ZiatHO717cEQHymLGWZ4CmYRXRAn6Ns= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774862062; c=relaxed/simple; bh=F2DTDMgwV3Y/ekPzFw0tACQfolXrQG9Q3INC7wJCU4I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mCAe4E9ieWrh0SBf/MhJc3AIg8h2Q7qq8rnPVxjumFJkFkGkwd8t+DDza6uz4i1XUsigkG5UEy9ku9L2eJwh3WxFPIXPrh3Aw8SWadxpdebtY6iU5pbS9VLC8QxcoeHvGVpuMgPRev/vPHVFA441d3xLeiQuMhsNeSbn7MgMbdI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=i1+KmTyM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="i1+KmTyM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 859E4C4CEF7; Mon, 30 Mar 2026 09:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774862062; bh=F2DTDMgwV3Y/ekPzFw0tACQfolXrQG9Q3INC7wJCU4I=; h=From:To:Cc:Subject:Date:From; b=i1+KmTyMuWARSmFI9KvD1/3FBivqVQHNdLYQ8R6HFuda3aLejoVYyKi+sbcGbQybq whzMz23rXD3V3AT0IrMLydHA395oSXV5BGalKxnnpjld97tYyePFI7BMHMGNScPU8P eGFfh0pDHbvxq81g8zMtq0qvTBGMd5cEUqPR8zls= From: Greg Kroah-Hartman To: linux-wireless@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Johannes Berg , Yuan Tan , Yifan Wu , Juefei Pu , Xin Liu , stable Subject: [PATCH] net: rfkill: prevent unlimited numbers of rfkill events from being created Date: Mon, 30 Mar 2026 11:14:13 +0200 Message-ID: <2026033013-disfigure-scroll-e25e@gregkh> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3473; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=F2DTDMgwV3Y/ekPzFw0tACQfolXrQG9Q3INC7wJCU4I=; b=owGbwMvMwCRo6H6F97bub03G02pJDJmn7J4W7VY5pjb7yuPUFgZZyaUXgg+yNDy88/Kj0rTiI 64LOH5IdsSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEpCIZ5nCdUel63y2/R1Lo i/Fz9QtcV77yGjEsOGKvPtXmXETh4Z1HhBau+j2j8ka+IwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Userspace can create an unlimited number of rfkill events if the system is so configured, while not consuming them from the rfkill file descriptor, causing a potential out of memory situation. Prevent this from bounding the number of pending rfkill events at a "large" number (i.e. 1000) to prevent abuses like this. Cc: Johannes Berg Reported-by: Yuan Tan Reported-by: Yifan Wu Reported-by: Juefei Pu Reported-by: Xin Liu Cc: stable Signed-off-by: Greg Kroah-Hartman --- net/rfkill/core.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 2444237bc36a..4827e1fb8804 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -73,11 +73,14 @@ struct rfkill_int_event { struct rfkill_event_ext ev; }; +/* Max rfkill events that can be "in-flight" for one data source */ +#define MAX_RFKILL_EVENT 1000 struct rfkill_data { struct list_head list; struct list_head events; struct mutex mtx; wait_queue_head_t read_wait; + u32 event_count; bool input_handler; u8 max_size; }; @@ -255,10 +258,12 @@ static void rfkill_global_led_trigger_unregister(void) } #endif /* CONFIG_RFKILL_LEDS */ -static void rfkill_fill_event(struct rfkill_event_ext *ev, - struct rfkill *rfkill, - enum rfkill_operation op) +static int rfkill_fill_event(struct rfkill_int_event *int_ev, + struct rfkill *rfkill, + struct rfkill_data *data, + enum rfkill_operation op) { + struct rfkill_event_ext *ev = &int_ev->ev; unsigned long flags; ev->idx = rfkill->idx; @@ -271,6 +276,15 @@ static void rfkill_fill_event(struct rfkill_event_ext *ev, RFKILL_BLOCK_SW_PREV)); ev->hard_block_reasons = rfkill->hard_block_reasons; spin_unlock_irqrestore(&rfkill->lock, flags); + + scoped_guard(mutex, &data->mtx) { + if (data->event_count++ > MAX_RFKILL_EVENT) { + data->event_count--; + return -ENOSPC; + } + list_add_tail(&int_ev->list, &data->events); + } + return 0; } static void rfkill_send_events(struct rfkill *rfkill, enum rfkill_operation op) @@ -282,10 +296,10 @@ static void rfkill_send_events(struct rfkill *rfkill, enum rfkill_operation op) ev = kzalloc_obj(*ev); if (!ev) continue; - rfkill_fill_event(&ev->ev, rfkill, op); - mutex_lock(&data->mtx); - list_add_tail(&ev->list, &data->events); - mutex_unlock(&data->mtx); + if (rfkill_fill_event(ev, rfkill, data, op)) { + kfree(ev); + continue; + } wake_up_interruptible(&data->read_wait); } } @@ -1186,10 +1200,8 @@ static int rfkill_fop_open(struct inode *inode, struct file *file) if (!ev) goto free; rfkill_sync(rfkill); - rfkill_fill_event(&ev->ev, rfkill, RFKILL_OP_ADD); - mutex_lock(&data->mtx); - list_add_tail(&ev->list, &data->events); - mutex_unlock(&data->mtx); + if (rfkill_fill_event(ev, rfkill, data, RFKILL_OP_ADD)) + kfree(ev); } list_add(&data->list, &rfkill_fds); mutex_unlock(&rfkill_global_mutex); @@ -1259,6 +1271,7 @@ static ssize_t rfkill_fop_read(struct file *file, char __user *buf, ret = -EFAULT; list_del(&ev->list); + data->event_count--; kfree(ev); out: mutex_unlock(&data->mtx); -- 2.53.0