Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp227338rdh; Tue, 13 Feb 2024 15:16:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXB9S3HjIgoP0ryAmnhx0YQPsD8PgMtxA+QRQLQdW4zO+jAarK5CndKcx5i16CnSK0zDfQSIHxt5EtTFMTS3Pt5/rxwmz89ltIuIPN5+g== X-Google-Smtp-Source: AGHT+IFLvOUmWCGUUbIZCFG708KaaXeD53WzHzdw617CtH0uu8SMU4aCbJfG5xPf/H5GrvcwjOQl X-Received: by 2002:a17:903:48c:b0:1d6:f34c:35d9 with SMTP id jj12-20020a170903048c00b001d6f34c35d9mr754742plb.58.1707866168003; Tue, 13 Feb 2024 15:16:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707866167; cv=pass; d=google.com; s=arc-20160816; b=hh/r1pTIE1UYC3O4qJa7tpY8hz10zV9mXE0bKadp8Xh8cYOcXmiYirhY/u/a/SKfrG vlK9svi7b2NGs/tYVLMXzfBhLVO0v/P4SO/sLySp6SCtLs0A0CJkS+lGEwZX6IwyYf4K PXD6zdqSjZ5RzYEx3+1BxmpWOr1bmaQFsH0i7vhVw4B1TomAwzqmOgV1gEy29p2/G4qF 2XZwIauXEHM2rqJ7ZeQE9yXpn9W+YpXknufAtjpH/1L3ACh1rCb0iyH038uQIFLlgNcZ Tgu/CDTfs7bLpY6s9grGU0TVQPlC5fzrB5KATdQXVRi+PpwiDxHSNxNnP2pd4YMvdxFs CWgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=u1sKZkLPjgDOF5m3bXTmn29vEuAR6iiKektHF/NRrR0=; fh=hL7s4XcY4cBciyJhqJJUoJi3HVkSkcg6uo7wIJ821Sw=; b=XsDhG9rm7out99uDlQUBY0YW4CQT/cQsm9J5ZFfaf/bF2yn7kK9pcwol36g+/3PzDV nfqJVuJx2Vpbw3kXFjTDit4fCmQJ1yXQVOKzROy42IbdzcG5X9ZkuMSIFqiDkrxfFQao ojwjeHk3ks7lMNEzpzcT7Os3wyA8464A8rmCBwpKCFlkNxcx3RH96GUKPKHzMlOz4xRp Vq5eJVM55ViserSfUWBWy7QM5cADKKXOxusvJLbBY5voVxIwf2qrbYQfE3cmKwPKiM8c xtNSPC+Y8/shVWoEAURfyo2Hd5v9YyI+nm8g74I+xyeDuU/XJOfL/axO6D0CFymgV+sF AfMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=EgHPKu9v; arc=pass (i=1 spf=pass spfdomain=fromorbit.com dkim=pass dkdomain=fromorbit-com.20230601.gappssmtp.com dmarc=pass fromdomain=fromorbit.com); spf=pass (google.com: domain of linux-kernel+bounces-64477-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com X-Forwarded-Encrypted: i=2; AJvYcCXPXZ0ugi+iRx++b76UN4G86p2cgncHV6+xPkuc5Rw2kRalVmSk/VOkxVlCXuTbczQjtK/6LjoYvjGHwxRmdatAjFNT8iyptjXgzdwxgQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f15-20020a170902ce8f00b001d9cfd20f7fsi2698298plg.473.2024.02.13.15.16.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 15:16:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64477-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=EgHPKu9v; arc=pass (i=1 spf=pass spfdomain=fromorbit.com dkim=pass dkdomain=fromorbit-com.20230601.gappssmtp.com dmarc=pass fromdomain=fromorbit.com); spf=pass (google.com: domain of linux-kernel+bounces-64477-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EAE72B2768B for ; Tue, 13 Feb 2024 22:44:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C4CE62801; Tue, 13 Feb 2024 22:44:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b="EgHPKu9v" Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 F367E626BD for ; Tue, 13 Feb 2024 22:44:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707864283; cv=none; b=PNbNtoswqa7l+jv2Edm+xP7UfZsQujK4Soz7e4Zgn6xJBwKeED55w1JxErogzJoew4dap8wSgVhvI+8/QAiNu9BR1xudaYbRK1KRhCM6DO8cJK/nE9H7oBbluvJwF1FZriEPQe3WOwMHFFW4fjb5MNmHDmsNTjzX/W0LUq/qQvM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707864283; c=relaxed/simple; bh=DkHZ2mjgTqxGFzmhJ0GZhDKs3oxoxJfE7ld+YCwH9JY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JCn4d88MUnMYQFBmHJXVzf6JCxy0d+wqGj/2RZtRqA1kdff73PMtqX4M/gkYqkisT3SKJolY2gYwxabvuuHeEXB5S28O658hUvmv83LCoP2MRTx1HvboM7zzhZoaUqktszoR9kmi9nhmNSEO9kUVTJYjVPDeRRpswrALRypAzAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com; spf=pass smtp.mailfrom=fromorbit.com; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b=EgHPKu9v; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fromorbit.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e0507eb60cso3186209b3a.3 for ; Tue, 13 Feb 2024 14:44:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1707864281; x=1708469081; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=u1sKZkLPjgDOF5m3bXTmn29vEuAR6iiKektHF/NRrR0=; b=EgHPKu9v+3GFnsl3y1lZDHpxZEqIkFI3reDPwhM/EoRbCPzmOnwM7TiWaFvDZI9Y5a Ub/vcCcluRTyabDkZB+B2wBAueSpYutmxH/02kgOIuQRV/MYKjwGButoFmo5/uY0y7Ii z4GWE0GYfTlrb8dWegen/WU0CXPceZR5JTJIABZGnCkDwZd6a2ivA+rNSr4xTnJpxxw1 z+BrcV/xIQpqx4bl64J9mDEbH88SRw4F5R8NsODSUT5NKaMaqMXqzTleJTgJTJbFlb6n ZJwonTn9vVKV28O2U4JEnrgt97QNqiNMKkf6BcWs+H+qoND5JYrisqBjAV4M1hPthqnR 4qgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707864281; x=1708469081; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u1sKZkLPjgDOF5m3bXTmn29vEuAR6iiKektHF/NRrR0=; b=qgV4iyb0A29RwRdMCK8oeJuUrxsR4h0WUADXbOvE6XKvEM0fm2J952anuechGq75pJ qXlxd9U6nyvDkD9L8Co86mnM/XucY2qbXvOFOt5alDSLrWcDkZF3a//5l6x4O22YQEja 78SO9S3yOJE8p3h/XVI9jHLDdPO4pzKIU4r583w9F9NlJ/njCIXnQBiPiOA/4QPstdZx pNhi3avZpIac5C4ziadYVi61yxTN/RtEq6bjaqpzrayGDcmS79ovBBKcmY3Y0VCpF5e3 eJ/PQUf7wV6Mc2UBVxjoeoPwskqV66/tkKqRLdRE0f2Vljk6D6yxcgOrzKRY6DNIxgTv mMYg== X-Forwarded-Encrypted: i=1; AJvYcCUFBUfHTyCb/he0YtnYHa+uBzlgwTTVKVp3pu9jLBUwNSuPDticFAmYz8F1BmqHyMA+2xnTqZZGzOCiCrbXk5sLz4+kEaZ42IvpdqS1 X-Gm-Message-State: AOJu0YyybFDlPkv5Ew3f8UQDc6mIkhvc1xc2Lg0SCmsvqE76OY6x46Qm jRwg4jmXi5Ddm78NU5KneFBJHOk6r2+deDH2AFmBoW/jU3h+0qNLLqZ4pZ8C9cc= X-Received: by 2002:a05:6a20:d809:b0:19e:ba40:83e9 with SMTP id iv9-20020a056a20d80900b0019eba4083e9mr1461948pzb.17.1707864281250; Tue, 13 Feb 2024 14:44:41 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXLIL+5HbWfGdrbIFKF29jZ7ekgxR3Cem75R2GxM2SCb2adZY4DmlDpHJDBxWhw5qcwpLxmaOOHL13+l7ewRF6slNN34C0Dtmv4tppu8BPbrWlpYoN/mBus0eEZiBc1GirGPpePLR0PlbCqHsiYq5lvQJXhvVqnSMv2vAaToodBoUu2x2ERjz0mmPTt5yMJJjIW3/heHmiJ/lzYRKmcpK/r91qVHRI999G5V14FkT+8zJ+jaFFRJG4d7vnpV2knDFWXhjsAZNapkWUR2hOeNE/U/hnSnjXPepPqJ0c4o4+0UWNP0k/LhCAb4F3qrPFni1SK8Oudg3w4mRVLSxOXM5nqMmjP/ZzTEydIiaMjBGttWrNbAx19Rdby6PC1gqcsA5JQlSFLhjCotVJgdF61kXdSTJfD7PdXFJ8Z70zB8WBzOBfyvw== Received: from dread.disaster.area (pa49-181-38-249.pa.nsw.optusnet.com.au. [49.181.38.249]) by smtp.gmail.com with ESMTPSA id n8-20020aa78a48000000b006e06936c7a6sm7948075pfa.200.2024.02.13.14.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:44:40 -0800 (PST) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1ra1W2-0068M2-0u; Wed, 14 Feb 2024 09:44:38 +1100 Date: Wed, 14 Feb 2024 09:44:38 +1100 From: Dave Chinner To: "Pankaj Raghav (Samsung)" Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org Subject: Re: [RFC v2 12/14] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Message-ID: References: <20240213093713.1753368-1-kernel@pankajraghav.com> <20240213093713.1753368-13-kernel@pankajraghav.com> <20240213162611.GP6184@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Feb 13, 2024 at 10:48:17PM +0100, Pankaj Raghav (Samsung) wrote: > On Tue, Feb 13, 2024 at 08:26:11AM -0800, Darrick J. Wong wrote: > > On Tue, Feb 13, 2024 at 10:37:11AM +0100, Pankaj Raghav (Samsung) wrote: > > > From: Pankaj Raghav > > > > > > Instead of assuming that PAGE_SHIFT is always higher than the blocklog, > > > make the calculation generic so that page cache count can be calculated > > > correctly for LBS. > > > > > > Signed-off-by: Pankaj Raghav > > > --- > > > fs/xfs/xfs_mount.c | 6 +++++- > > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > > > diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c > > > index aabb25dc3efa..bfbaaecaf668 100644 > > > --- a/fs/xfs/xfs_mount.c > > > +++ b/fs/xfs/xfs_mount.c > > > @@ -133,9 +133,13 @@ xfs_sb_validate_fsb_count( > > > { > > > ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); > > > ASSERT(sbp->sb_blocklog >= BBSHIFT); > > > + unsigned long mapping_count; > > > > Nit: indenting > > > > unsigned long mapping_count; > > I will add this in the next revision. > > > > > + uint64_t bytes = nblocks << sbp->sb_blocklog; > > > > What happens if someone feeds us a garbage fs with sb_blocklog > 64? > > Or did we check that previously, so an overflow isn't possible? > > > I was thinking of possibility of an overflow but at the moment the > blocklog is capped at 16 (65536 bytes) right? mkfs refuses any block > sizes more than 64k. And we have check for this in xfs_validate_sb_common() > in the kernel, which will catch it before this happens? The sb_blocklog is checked in the superblock verifier when we first read in the superblock: sbp->sb_blocksize < XFS_MIN_BLOCKSIZE || sbp->sb_blocksize > XFS_MAX_BLOCKSIZE || sbp->sb_blocklog < XFS_MIN_BLOCKSIZE_LOG || sbp->sb_blocklog > XFS_MAX_BLOCKSIZE_LOG || sbp->sb_blocksize != (1 << sbp->sb_blocklog) || #define XFS_MAX_BLOCKSIZE_LOG 16 However, we pass mp->m_sb.sb_dblocks or m_sb.sb_rblocks to this function, and they are validated by the same verifier as invalid if: sbp->sb_dblocks > XFS_MAX_DBLOCKS(sbp) #define XFS_MAX_DBLOCKS(s) ((xfs_rfsblock_t)(s)->sb_agcount * (s)->sb_agblocks) Which means as long as someone can corrupt some combination of sb_dblocks, sb_agcount and sb_agblocks that allows sb_dblocks to be greater than 2^48 on a 64kB fsb fs, then that the above code: uint64_t bytes = nblocks << sbp->sb_blocklog; will overflow. I also suspect that we can feed a huge rtdev to this new code and have it overflow without needing to corrupt the superblock in any way.... -Dave. -- Dave Chinner david@fromorbit.com