From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (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 1506320F095 for ; Thu, 23 Jan 2025 12:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737635596; cv=none; b=Rp3CNYW95JeXep3rau5Sd/nwRgb52h6dPzLvN7tfRY1ocr/e1WNodeI27fFRUiK4CTU7Hy9fagVdNBQK+xWgtCQ86qhA8omobSWfTIXNdnNrfNkNUo7c70oneUzuyJnTHhm7AAiauMz/0pOleZ2y33Xp/fB2TZLbWt2ZGgoqiW4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737635596; c=relaxed/simple; bh=eN2NwzDCq8AKqVoBz0SQAD+2xxELeXCSoeB/C7IJZXM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MYwKjC47bo6c1UWq7kB88HV9irOnCQtsJnDuUo4CnWwBd7GJTwd2OIPZUM1Z2Btufyo73nDBbsbxCoJkdfCedmPARfQDO2kwmiZaaJJXPy/dsGRGCIainXQjx/nYxcH3eVUb4ETlhb9LBrt6AoFosOv2XFbiU921YVTY/yAKpqc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=l6qfud5p; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="l6qfud5p" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=nH9ot4bqj3q3bMquAfmURiDQsYK6EZv7ECena6dqKmc=; b=l6qfud5pM4nff8ZeDtu7AjNpLh tbiVQnyvQ2ZkIxdhQwIFeXZ1L00eiTP5JLAeqVvM8EJ/6Is+P05tNUeXgGJH8gk+5Q71e/4Hgh3oM tl5pZ9JYII3/twuM+9T+eP8L1TT6XS5O0HabTvPxKhntfUHqTcR/Um17CQ1XdOWu6xSaL4ntwLPYV N80gFi34Z5B6UqALj3ojf8Jy82xsrIeC9IIYQjRBtyj/bVMCrz7WrZxyWLXeAnGjgoHtAn4YyOUGT CnikpcTFa4fJVg9Fqg0lvPLOv6zYy4QqKLzl/AU/kt5yNcQuarjOfTs1IuDZdEuOwvvC2hO8HzfkM JCGvlsQA==; Received: from [177.180.73.242] (helo=quatroqueijos..) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1tawOW-001CCB-Mg; Thu, 23 Jan 2025 13:33:13 +0100 From: Thadeu Lima de Souza Cascardo To: linux-kernel@vger.kernel.org Cc: Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Dirk VanDerMerwe , Vimal Agrawal , kernel-dev@igalia.com, Thadeu Lima de Souza Cascardo Subject: [PATCH 3/4] char: misc: restrict the dynamic range to exclude reserved minors Date: Thu, 23 Jan 2025 09:32:48 -0300 Message-Id: <20250123123249.4081674-4-cascardo@igalia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250123123249.4081674-1-cascardo@igalia.com> References: <20250123123249.4081674-1-cascardo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When this was first reported [1], the possibility of having sufficient number of dynamic misc devices was theoretical. What we know from commit ab760791c0cf ("char: misc: Increase the maximum number of dynamic misc devices to 1048448"), is that the miscdevice interface has been used for allocating more than the single-shot devices it was designed for. On such systems, it is certain that the dynamic allocation will allocate certain reserved minor numbers, leading to failures when a later driver tries to claim its reserved number. Fixing this is a simple matter of defining the IDA range to allocate from to exclude minors up to and including 15. [1] https://lore.kernel.org/all/1257813017-28598-3-git-send-email-cascardo@holoscopio.com/ Signed-off-by: Thadeu Lima de Souza Cascardo --- drivers/char/misc.c | 4 +++- include/linux/miscdevice.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/char/misc.c b/drivers/char/misc.c index 2cf595d2e10b..7a768775e558 100644 --- a/drivers/char/misc.c +++ b/drivers/char/misc.c @@ -68,8 +68,10 @@ static int misc_minor_alloc(int minor) int ret = 0; if (minor == MISC_DYNAMIC_MINOR) { + int max = DYNAMIC_MINORS - 1 - MISC_STATIC_MAX_MINOR - 1; /* allocate free id */ - ret = ida_alloc_max(&misc_minors_ida, DYNAMIC_MINORS - 1, GFP_KERNEL); + /* Minors from 0 to 15 are reserved. */ + ret = ida_alloc_max(&misc_minors_ida, max, GFP_KERNEL); if (ret >= 0) { ret = DYNAMIC_MINORS - ret - 1; } else { diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h index 69e110c2b86a..911a294d17b5 100644 --- a/include/linux/miscdevice.h +++ b/include/linux/miscdevice.h @@ -21,6 +21,7 @@ #define APOLLO_MOUSE_MINOR 7 /* unused */ #define PC110PAD_MINOR 9 /* unused */ /*#define ADB_MOUSE_MINOR 10 FIXME OBSOLETE */ +#define MISC_STATIC_MAX_MINOR 15 /* Top of first reserved range */ #define WATCHDOG_MINOR 130 /* Watchdog timer */ #define TEMP_MINOR 131 /* Temperature Sensor */ #define APM_MINOR_DEV 134 -- 2.34.1