From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (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 507B141C313 for ; Fri, 1 May 2026 18:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777661998; cv=none; b=ZjmaHHMTDImCkwNHalUS1sf75HIk/L7QtH7x2I30jrUrpk8uqinHweV870nnvqJV9egbJP8A43q/FPs+s0VvJ+NWd2fPIynduky3R1M16ad6DM5lDYLKLiv8I/8Fg8Ci13I+wkjbsdy6xy/8AnKdjj0lnCl53DlfkmsPjbb9g/4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777661998; c=relaxed/simple; bh=HWvQXvqZy+2hPEYEMo0v3KN27sov3PyJalKAxSo7KpI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qKtxWI32yFjQLwiKmh6clziogSQB/GPHT7hktwnMhQOeWsGAMfW7ARyC8uWfLZnnySHnGkd006+enO5PGwkw7QnJHB+j3q73PCS47g3ltuzZYWZ2Vg1ADLu6Z5BftvRjCEQYGFqrUZ8dum7FmrclEyCRS1funCHHTcYiycqTa0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=PVJqxjDj; arc=none smtp.client-ip=209.85.160.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="PVJqxjDj" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-50e63771eb0so20990591cf.3 for ; Fri, 01 May 2026 11:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1777661989; x=1778266789; 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=C3umcs7hPnTIt6bZruKgswwIksEQkK1T++wSCt9dAno=; b=PVJqxjDjO/WRTialxR2TwLtzVYy8YbUYqSOSRria2l6IJqN058yq0ZOrxvcw2cNv3D 4iMYC1HKTKcHlE5mpxhuzgQWtvBwlvzh5VSShXOIFwD+sJjC+oCjWMOHf5MFZswRBqRL DwPHj77NdcgyPaPJFRHrjPlpE5GCFhxL60iR6N1+r95bn844Uy6nstNWnX/nZecSJBAv wPjmfnxPjqEkFIPUNlGtFR0asDoW+NrvxV18ZKRV5yxpadKtdDvfvsVGpXwJoMWY06mU n2gitaBSqgA7LIbYjkodwcRKX1nNTpO82j+bSkmVHoFrJBkBtH9Icw6Khf0w8yQWSuwT 4NZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777661989; x=1778266789; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C3umcs7hPnTIt6bZruKgswwIksEQkK1T++wSCt9dAno=; b=U2zr95NbSMtF5Z2XfBu1kCOx1ChwucbOpQyWJzoeLTHJy1CVIHggWYtdfyI150FtpU 0FkGR1VVH9RUs2HUPa7cNwU9je+n7mPfdyJf6dQHkZLhRiM6GoXV51ToQZ5z9mH8bi9i phumFCD6vjErIz0Q/J5WSXb9KTHiqq9zWCp+3RL1JfbLKrFltjKyBy8eICF7qq6Um5Fk SVEqNmVj2oPnHun10g0KLlRbG0A9fDLpdu99/L58Ga4ySmwMuwPYQ0AMnzG+r7F4+gU1 xz5Gex59Rq5xGahiGExtQ7lnKUORqAHsqJNGwXrFZS8RLAUXoQRzqWKky8yfDar5fcqe pGPA== X-Forwarded-Encrypted: i=1; AFNElJ9+Rzb88zBy90Z4NaiLIapEscJH4liyF1XWFFGzOOFdcavFpResjRNbB9ITcjIiA/Y2IC1H7UD1J5RtVuA=@vger.kernel.org X-Gm-Message-State: AOJu0YyAGKMxr6EBirH/4DcnVv7OPzm/E6zBg+KU2jBTMqlMtsmK4CHq oRhJfz+ZoHhz2fU5G6yEWRd9rDS0icEH5BycSYGSW5eXyuf1qAOaT6tnLN4KswKJK9Y= X-Gm-Gg: AeBDiet4CTV9NhY7PwTM/4NQIZBa+lf2TuRfzirCoQs/Xjn0up9t+M09iR46rf+abml UvomW46WZtvCw+QF6+9U24a7MJYWzvgkc+Lpx6KHUqzRQ+9CSc8oyLlnh8f9uIVrAyP1SDh9BXa UcNbr7gj36Lz/Sduwn8aED+zOUJv5xWOMSOkC05P9bme4vuLb0wBp6We/JKUTZn8wxCu6y91KYr rXbUTKXlI7hrgZz3xBqC/vsDfmSunwj4VwyxcOpGN+r4Fh55AQLHGhwN5Ov+Z/sJdFQn5tZFBSR ajioAPULzS4SRpmy0ztLizTRz+Jy2cuZL0KD26ICzLp1h1LJG1Qy1Pty24ZlxiUbtkYgHFQ1Ldt MPJe1lHLMTnpPl8zjIf1gy1p61rHQ8orTOi5ZoJE163q9MnWkb3Hcd0wJD1FDidBFIjcOApcp+n 6iIn50IsrxMoo1nqIq3rKpSd3Vogo/Q6cb5leKCt6Szo86R237E3tKs1b1ErHCvA== X-Received: by 2002:a05:622a:408f:b0:50f:be8b:f803 with SMTP id d75a77b69052e-5104bf0a257mr8184361cf.29.1777661989331; Fri, 01 May 2026 11:59:49 -0700 (PDT) Received: from plex ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-51040908d6bsm21660101cf.7.2026.05.01.11.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 11:59:48 -0700 (PDT) Date: Fri, 1 May 2026 18:59:47 +0000 From: Pasha Tatashin To: David Carlier Cc: akpm@linux-foundation.org, pratyush@kernel.org, pasha.tatashin@soleen.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm/memfd_luo: reject memfds whose page count exceeds UINT_MAX Message-ID: References: <20260423125648.152113-1-devnexen@gmail.com> 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: <20260423125648.152113-1-devnexen@gmail.com> On 04-23 13:56, David Carlier wrote: > memfd_luo_preserve_folios() declares max_folios as unsigned int and > computes it from the inode size, then passes it to memfd_pin_folios() > which itself caps max_folios at unsigned int. For files whose base-page > count exceeds UINT_MAX (larger than 16 TiB with 4 KiB pages), the > assignment truncates silently: only a prefix of the file gets pinned and > preserved, while memfd_luo_preserve() still records the full inode size > in ser->size. On retrieve the inode is restored to the full size but > only the preserved prefix repopulates the page cache, so the tail comes > back as holes and user data is silently lost across the live update. > > Reject such files at preserve time with -EFBIG rather than chunk the > pin loop, which would also require enlarging the preserved folios array > well beyond what is practical. > > Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd") > Signed-off-by: David Carlier > --- > mm/memfd_luo.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c > index b02b503c750d..f41d11053b7d 100644 > --- a/mm/memfd_luo.c > +++ b/mm/memfd_luo.c > @@ -259,7 +259,7 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args) > struct inode *inode = file_inode(args->file); > struct memfd_luo_folio_ser *folios_ser; > struct memfd_luo_ser *ser; > - u64 nr_folios; > + u64 nr_folios, inode_size; > int err = 0, seals; > > inode_lock(inode); > @@ -285,7 +285,18 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args) > } > > ser->pos = args->file->f_pos; > - ser->size = i_size_read(inode); > + inode_size = i_size_read(inode); > + > + /* > + * memfd_pin_folios() caps at UINT_MAX folios; refuse larger > + * files to avoid silently preserving only a prefix. > + */ I think, the fix should be first done at memfd_pin_folios() to change max_folios to 'long' or 'unsigned long', and then just updated memfd_luo.c to match. Pasha > + if (DIV_ROUND_UP_ULL(inode_size, PAGE_SIZE) > UINT_MAX) { > + err = -EFBIG; > + goto err_free_ser; > + } > + > + ser->size = inode_size; > ser->seals = seals; > > err = memfd_luo_preserve_folios(args->file, &ser->folios, > -- > 2.53.0 >