From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57ED0345750 for ; Wed, 17 Jun 2026 21:57:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781733466; cv=none; b=VF84j9akgwr5a6Re7Dsv6vz7JkEWi+UjPofOyx6w/Hs97cgK6RWdbL3H48SXpSe9+8wU2lyzHWwNLcY6v0l7dXVnyNeijHk7Jr3ilHOMIOK+gfOMlGkG+CiqMfNt266Toq2RMRMAaCo6aB6ROP/Gc/k8ng4tx5ghLiPTO6fMKNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781733466; c=relaxed/simple; bh=F2oBa7aj08WRmmdx4CITKCkwSJgoUL1aqkWZdc1NHdY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=csUH8fy2T5LaZYN7dJsAW/H20YAzvFD2mmb2WCDwy9x7O+TIWYN868CxtIAvEvnKep9oIIWoy6Asv12bEv0VJ5Lq2zU8EjxIKY/pOPrxzqV16CxqXV2QyZX81J9pht2OW9drZ/SCNZJfiLYzhteUkHgV/3Fch6MMvcH3sOLZRmo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NsD3svu3; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NsD3svu3" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-8ccef25789fso1656936d6.3 for ; Wed, 17 Jun 2026 14:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781733464; x=1782338264; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=PVwNjFuEyUh+SBAQwHYwKAtynKLgHX4Q8K2y3LWjGNc=; b=NsD3svu3TlVUgA7qRgHdO6ElogDzBcTsYfblAWxVyFYUVG4imYIR5ojMjpg4uD3Pwn Wp4dkD6vASIP/FgQl2Jkpr9wUnsNfOKVp+QjqgB0lnj2Dzx98O87Z4r3odePAJX2pv+n NBLnWWmFkX4Xyf6RWGOWhUkqpgbEIgIz2KBCOIshMj2mW/x6R7p3eCmoN6wGJU29ndUF KTNYj3hii1WmaMXcU4xfPrUqnH6PNMnOyy8NRGbehacXpkQxWUcN+bFtbj4touku7P+G 4fpGkDuwLKIwgpXKMLaKYe5PDCusuuBz0F83/aa9xp4tn71YqAvNKOS263AY1wqMqJC7 WwLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781733464; x=1782338264; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PVwNjFuEyUh+SBAQwHYwKAtynKLgHX4Q8K2y3LWjGNc=; b=aEOHl6OF3C7GzWiV44xtC1AekwO3xFpUEHAf4+u/ovgXU2WvFkGuZM7UbYUNPVs7Ke wrYx0UorRHYP1nB/VgUCRjTZx5YM1DdWBSAH8MYLzN0vCesdgn4R42fnz7kFkAl4a3qY MyoZr9ycjQEeC0kZ03QWaVJfFCmtNZQyiPJ/ubgqaOSOoEwRPcvFJ1AvvvtqvJv//oeJ jimIkzxVl3Lfh8MAG8oS3Dl0sp0utr+T0fY4htzdpwf8pfnMVNZnBUXQpAaBocu8Naxz o0zQADsuGiWlrpl+825+FohQkLe/pn+0xSQboK45IRLVHgnMylZ8zYzbKgLDUXkWX7/4 0mPw== X-Forwarded-Encrypted: i=1; AFNElJ9Qaus9wu4hfTbmVCSDhOGljbjszuKRCcI91kBhVYT7qAYqCeongYF0hROKIrIpzpBKonsvQdrjBwpRYIk=@vger.kernel.org X-Gm-Message-State: AOJu0YyR1KOG0n3+90XkvAV2thYvICYLREQ06/Ub4KtLErP58MkoVFer BmSRxxktbZxhe7JMAPNJDBr3i5RX+wZ9RxgUqWyv4YbUJ8oalO0Cqi3q X-Gm-Gg: AfdE7clkZn+XRJbn6GzhOSKSrnk/Jji8KUD42FnHC29TjIeCU9RCGgXVz33ijEVkWtY i+qxvdjH/59IeDahg6S+fNrQY94/pEQbtMxMhlkyODQymZgRt0GRjm5CXJ0/pVLuMX+hMHzfYkp HfBkLdyOHgec7Q+IkBnyDhG7BS0EIAbqE9pAt+QEbKtjxWNYLuZLF05yq0FDwcLjdnnlwTg+Tv7 Iq9y0l+o+xv2BnUvKP3fpXx46UDwxBycnct9QT0+dEBwflvArUsM5cSE54nlvQRfHbZsg8etB80 OuTMiFhBGsY9Bzi+eazqxBMN3i5LO1DjGmDiiw+RKRq8jiFPa6gzL8sS09wOJvAI4i1fWCwxgHW yRAksIsw1UV4/pwcP1EulKiCLJvW4d+nZ0MwGgvx1LsPpbC1t9nVC8VF0QCs6q9n9mWWfrQReRT JlWVOJCwi/jLCX5xxiZOTVOmC0H23QxaAnz73pGf+Td5X72Aw67Tz28ZFgQsSiLqGcNIkAgE0m2 kfPmpGyOWjtCD7O2P9fpKE0OReiH5// X-Received: by 2002:a05:6214:187:b0:8ce:a033:eef9 with SMTP id 6a1803df08f44-8db5ca19211mr80317266d6.26.1781733464294; Wed, 17 Jun 2026 14:57:44 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8dcf3cf5552sm4252196d6.39.2026.06.17.14.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 14:57:43 -0700 (PDT) From: Michael Bommarito To: Jan Kara , Christian Brauner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] minix: avoid overflow in bitmap block count calculation Date: Wed, 17 Jun 2026 17:57:40 -0400 Message-ID: <20260617215740.1116778-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit minix_check_superblock() uses minix_blocks_needed() to verify that the on-disk imap and zmap block counts are large enough for the advertised inode and zone counts. The helper currently performs DIV_ROUND_UP() in unsigned int arithmetic. A Minix v3 image can set s_ninodes or s_zones near UINT_MAX so the addition inside DIV_ROUND_UP() wraps to zero. That makes a zero imap/zmap block count look valid, after which minix_fill_super() can dereference s_imap[0] or s_zmap[0] even though no bitmap buffers were allocated. Impact: mounting a crafted Minix v3 image whose s_ninodes or s_zones is near UINT_MAX makes minix_check_superblock() accept a zero bitmap-block count and minix_fill_super() dereference s_imap[0]/s_zmap[0], panicking the kernel. Calculate the required bitmap block count with 64-bit arithmetic. Return it as unsigned long to match the superblock fields and local comparison. Fixes: 8c97a6ddc956 ("minix: Add required sanity checking to minix_check_superblock()") Assisted-by: Codex:gpt-5-5-xhigh Signed-off-by: Michael Bommarito --- Testing: integer overflow (no sanitizer); the oracle is the downstream NULL/ZERO_SIZE_PTR dereference crash. Reproduction (UML mount, same crafted image, before/after): a Minix v3 image is crafted with s_ninodes near UINT_MAX so DIV_ROUND_UP(s_ninodes, blocksize * 8) wraps to zero, then mounted from /dev/ubda by a one-line init. stock: RIP: minix_fill_super+0x3f6/0x5c3 ; Kernel panic - not syncing: Kernel mode fault at addr 0x10 (ZERO_SIZE_PTR deref of s_imap[0]); UML exit code 134. patched: "MINIX-fs: file system does not have enough imap blocks allocated. Refusing to mount." / "bad superblock"; mount fails cleanly, no crash. A KUnit case additionally asserts minix_blocks_needed() no longer wraps for near-UINT_MAX inputs; both run on stock and patched. Conditions: CONFIG_MINIX_FS=y and an attacker-supplied Minix image is mounted (CAP_SYS_ADMIN in the mounting namespace, or a removable-media automount path). v3 only: s_ninodes/s_zones are 32-bit; the v1/v2 16-bit fields cannot reach the wrap. Mitigations: do not mount untrusted Minix images; most distributions do not enable CONFIG_MINIX_FS. No sysctl toggle. Harness (init script, crafted image, KUnit) available on request. fs/minix/minix.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/minix/minix.h b/fs/minix/minix.h index f2025c9b58252..8dc83f80bd768 100644 --- a/fs/minix/minix.h +++ b/fs/minix/minix.h @@ -95,9 +95,10 @@ static inline struct minix_inode_info *minix_i(struct inode *inode) return container_of(inode, struct minix_inode_info, vfs_inode); } -static inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize) +static inline unsigned long minix_blocks_needed(unsigned long bits, + unsigned int blocksize) { - return DIV_ROUND_UP(bits, blocksize * 8); + return DIV_ROUND_UP_ULL(bits, blocksize * 8); } #if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \ -- 2.53.0