From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 0307F2FB97B for ; Fri, 17 Jul 2026 10:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284775; cv=none; b=BKSTqKhp03X2otPt1Dgy6zyQRpYCePOB6NZSrGbXw/e++ahc2Uj77uvTidzI8Ovb1VzieaZIaczLxRH5g1XBzMi8nPlG6aZ8BsJQj+oMTfiFP9v+V/sbQ99IdQH9XvXt5LpCWVFSn7M4bsZydRUodoSSR2I66R+0G1IWdrjRvzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784284775; c=relaxed/simple; bh=r9NnbXQcdeFKjOIHprLKGbVoaLpN9o/euizgMg43/6E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hQpxzjQ3r2XXD58EiNGqPRmQpQ82QSzhHWUbV77Ydg4qIQZsouENMJoOXhBtzA5NO6zMMDsuRK9J7zEZDM9r/tfrLazskahvcz/XM6GELInPuhyv7NmWvLIQLa93v/jnld4pk6Xx03qltXFnXuYLajbKc1XMf5FRmfAYeEYrI4k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=NiaFRfya; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="NiaFRfya" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-8eefd4a8057so37853546d6.0 for ; Fri, 17 Jul 2026 03:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1784284773; x=1784889573; 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:content-type; bh=2gJk7PB+IrlJDl6EL2sp9rxsKZ7sqVD3VCH0jk5iNUw=; b=NiaFRfyanrZOtnv8xHnaQEa6HdiXCYPiNxbf1Dz/H0Pzw1x3tTpDFUm8ZmQSlB66aF IK6VjsLQ7eESkydvIMzUkFlZTv7pKNVEzOLNn9WXZM59YPlTP6PQv4MhPjkZoFcpCyNR 6mQ2eF0yUDkRl67wjqP9SFTXaeIBrEyuw4zavQQPMlr34SEi+Zzja6dsQlOwZ6caZ6Ce 2DK/3cu4P++n4tZ1hVyzqxQPuetQKal6fKuKoZ4Dm65Br6xwlrp/y5nLIqzvrrQ/CzhZ bjreHoyr1ah4o8Y7/v7G21e0R2hYkccR57VTT+2i+lLSGi76yCNB3cLK/+0Xqr9TW7DF 9+TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784284773; x=1784889573; 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:content-type; bh=2gJk7PB+IrlJDl6EL2sp9rxsKZ7sqVD3VCH0jk5iNUw=; b=CpPZrvVmO9aRb7HkMA0419BuEXL3lTzdOGS7pVFBr5A+QkbepcQx3hzmx9Tvt0RAQX dz4lqGAg66zsg3WzzTkZx40zrNwof1OwAScY6KbVyrmcELxw2MMSyzCYd85onMrNldRD Zbt3JAuN7ck6m1bf7bFO8KdEetnTh8cWy1qnqHRxpMUpJMd6uoPjFuYRhmSm4gkHD5po KkybgrklhSfr0GuJBU3PM0LupgLxhCBvueKfSD+bhe+KC9ClURTCPNFAgwXQtieGvfqU Xps+lY8VncZuuCWS9QRqvMJb2VFTIaziKCKzum56ozUM83EMjzIMaih44FaYFTK/pSlO 9m4w== X-Forwarded-Encrypted: i=1; AHgh+Rq+vVJeEC6wkdJhwLUDgh2FqH9919ULIzkU0vNQpCzhQGs0tWVIVxW4mjm3ONyZHr5vObO3EpwzyubPmUk=@vger.kernel.org X-Gm-Message-State: AOJu0YynIqxrQJI6sEHJlWalj7BjvYexSngxrg8aOnsfcTjnyS+YdEMn qaaEqSodzNpw2Trm2v9CT48Nv3biUQQxBo0oSkEJB27l3wBr4RPBAp2UDM1CnPQcQiAino9oQaO SQg2L X-Gm-Gg: AfdE7cmdqL66OuE4Dkpdb0gnJkj/SmNzze7wwm/Y4Az9XvCgqpW67Z0/YjhEblrGanZ ffstpfCs+oo9IEP+p5tmxoGiUCW7dipQ0wKkyY9eA3zdTDGvr3je+HhfVeNnMW+tPWJwiIs+Z9i nWVapCzWEYU+84/uYkUllGPfq4fdoGlwILtMGih1RMi5t6pAnXvLTiWYyb6yCcBvqSjyBfknXaU LuJxD/cepq68Ih2utm0RZNzBlBBtJLbGxB5OMDY3aQdc4GhwaCWI90xHwVX0J/NvAB7Po7EBUIl O4rsV1+VsP4Tfc/epF78+OpVsmJ2qq2t0M6/xppfOivL/kyO0h17BCKElaOLFelSXWrcHTkHckx h6xWFS+y177ioyT2knvY4GQhVnvMI7gzluH+EBVxzmP7ezkWlXcMt3a3+i5RMHLcpDQhzCW33wa cxVksQ89Y= X-Received: by 2002:a05:6214:2b8e:b0:8f0:2653:4a9b with SMTP id 6a1803df08f44-907783a0563mr20677296d6.39.1784284772749; Fri, 17 Jul 2026 03:39:32 -0700 (PDT) Received: from localhost ([146.190.222.192]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-90778541ffasm13729926d6.10.2026.07.17.03.39.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jul 2026 03:39:32 -0700 (PDT) From: David Lee To: Bob Copeland Cc: David Lee , linux-karma-devel@lists.sourceforge.net, Dominik 'Disconnect3d' Czarnota , linux-kernel@vger.kernel.org Subject: [PATCH] omfs: reject clear ranges past the bitmap map array Date: Fri, 17 Jul 2026 10:39:30 +0000 Message-ID: <20260717103931.38537-1-david.lee@trailofbits.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit OMFS stores the in-memory block bitmap as an array of bitmap-block pointers in s_imap. A clear request is valid only if every bit in the requested run belongs to one of those bitmap blocks before set_run() walks the run and updates sbi->s_imap[map]. omfs_clear_range() currently validates only the starting map. A corrupted extent can start on the final valid bit of the final bitmap block and request more than one block. set_run() then increments map and dereferences sbi->s_imap[map] past the allocated pointer array. Return before set_run() for non-positive counts. For positive counts, compute how many bitmap bits remain after the starting bit and reject clear ranges that would cross beyond s_imap_size. Fixes: 36cc410a6799 ("omfs: add bitmap routines") Signed-off-by: David Lee Assisted-by: Codex:gpt-5.5 --- Trail of Bits has a reproducer that triggers a KASAN slab out-of-bounds report and can be shared if needed. fs/omfs/bitmap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/omfs/bitmap.c b/fs/omfs/bitmap.c index 7147ba6a6afc..6420a3034a82 100644 --- a/fs/omfs/bitmap.c +++ b/fs/omfs/bitmap.c @@ -177,15 +177,22 @@ int omfs_clear_range(struct super_block *sb, u64 block, int count) struct omfs_sb_info *sbi = OMFS_SB(sb); int bits_per_entry = 8 * sb->s_blocksize; u64 tmp; + u64 bits_left; unsigned int map, bit; int ret; + if (count <= 0) + return 0; + tmp = block; bit = do_div(tmp, bits_per_entry); map = tmp; if (map >= sbi->s_imap_size) return 0; + bits_left = (u64)(sbi->s_imap_size - map) * bits_per_entry - bit; + if (count > bits_left) + return -EIO; mutex_lock(&sbi->s_bitmap_lock); ret = set_run(sb, map, bits_per_entry, bit, count, 0);