From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (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 4BCC4400DF4 for ; Fri, 12 Jun 2026 16:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781283499; cv=none; b=Bz0CjQHyjxgq5LmlwBPoEFsDZEmk+KFytK44ZOQTnGesxtocU4yx5ODe09brPCikBTGEgrAsdhTr2I7FC6APeME1UWeOlVAMXTKNMRBwrSjrHcO48MPscmsw68bK7Cgr/rXnLiqDEBPfucFvPzjhlYvK2pomHNzye5Nqtb9hWUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781283499; c=relaxed/simple; bh=AvRjRPICEywKthpMMEnUwlNg74Dv/GXFcGwC9TidY64=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Szg519LCm8IVlYZKUHl0msHKaSKPxuGsKZglJNlnYM8s05TfZG7GZ1YecqAM8O2CdXXP2UbgTunMh0mRxmmot4xi1MK3zQ6ZssP4ucI4/8wh7VKw3d+rnOuwzPFit5OtWH6XrIJn8nJy97PW11SuA6/ZCQvptpIvhAq3iC0i3yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qLoVvPn/; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tarunsahu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qLoVvPn/" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-68f9ee927fcso970125a12.3 for ; Fri, 12 Jun 2026 09:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781283497; x=1781888297; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pDX0q8phcP9mhqW5SB+yIq6adpUV680tO/gbdFTi4bg=; b=qLoVvPn/w4MSFTYWuzqRIYj+H3M3/3RYLWUFLbUGykcOprmpL/glT2qQaUDDIIrb/S 4G6Adjc3Jb/Pjg83BhzA1mOEeoLvlWksmQAIu+0MU0drFAENCrkbmF4BkVwgihiaRXCa nO2WBbbkZ4lePNKAMA2uZhtdgDCkfBJtiBjM4x+e6Fsj4yrkIGzFVHNf0aD4xlgHp6Pt FNjEclAZL4gSb+QYpgtFavbao9QStO29clJRZDwCQ1p3C+Uj9pU6JYjE6Uxn2UA4ZNQB BvaDXyLUAMcHZe5+palPpGglSgAgkGOql8EkvaKEZre39NNLX1P3pr7pYRlgdRPxk9KE 3Tug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781283497; x=1781888297; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pDX0q8phcP9mhqW5SB+yIq6adpUV680tO/gbdFTi4bg=; b=F7ZXwfMwHoT7FI+sy1HoVL/ZTC0xOVz/+OQHVNe3zel8qHl83mW1OdP4hjeINm37oF aGNDScCdb/HL74q+aJ1ZT7M8KPERWXndFMV1Zdrw3CYU2rgnqlmmXmvNlESrMDozvM33 Jj3mJNIzX6SJBeZf4ZcBshSAoqHUoJAQ2WBs2xnSldjkJcOmfHtVnwakl+0cyMD8DS99 uapZ7xdhnUFFu2OjMOMZ0VMhkEkX0+VzyAuXLeyQ39rqHcRGPO4bfny+4npCDmb/Yxoq WxV+z1tLOnmsUcHsj60bcRaGJ5oHYmEx/R8n+wa7rXihFR8KsGA055t+4s86dvea//mb kIBQ== X-Forwarded-Encrypted: i=1; AFNElJ/VWSf7nl/U0ejfApqCqTbHPYLkT7rSPKiQrdIFaXHlCtWNKQCLDPTX0JEI0/wCXk/c8IlwFOqgV7RfdO4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4lzvutkoJeTopZr+c3wnQyqFBK+etnlTFtQkaCODoMcImB4Hk AW+qVmcgeoqMpKPdU7ZYX7c/hOaetb2ZQRCrFH8YChmQcUMJ/0oMbpznue6hNNwZBgA+5MgAyWG 0RDnVlQpBY+lK4UK1lw== X-Received: from edi8-n1.prod.google.com ([2002:a05:6402:3048:10b0:691:a21a:fec0]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:5405:b0:68b:f026:f381 with SMTP id 4fb4d7f45d1cf-693787ed75bmr1752058a12.8.1781283496255; Fri, 12 Jun 2026 09:58:16 -0700 (PDT) Date: Fri, 12 Jun 2026 16:58:15 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <2vxzmrx1qjuf.fsf@kernel.org> Message-ID: <9huzqzmbelw8.fsf@tarunix.c.googlers.com> Subject: Re: [PATCH] mm/memfd_luo: validate serialized_data before conversion From: tarunsahu@google.com To: Mike Rapoport , Pasha Tatashin Cc: Pratyush Yadav , Andrew Morton , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Mike Rapoport writes: > On Thu, Jun 11, 2026 at 06:11:13PM +0000, Pasha Tatashin wrote: >> On 06-11 17:28, Mike Rapoport wrote: >> > On Thu, Jun 11, 2026 at 03:37:12PM +0200, Pratyush Yadav wrote: >> > > On Thu, Jun 11 2026, Mike Rapoport wrote: >> > > >> > > > On Thu, Jun 11, 2026 at 10:30:03AM +0000, Tarun Sahu wrote: >> > > >> In memfd_luo_finish() and memfd_luo_retrieve(), phys_to_virt() was called >> > > >> on args->serialized_data before checking if the physical address is valid. >> > > >> Since physical address 0 does not map to virtual NULL (due to direct >> > > >> mapping offsets), the subsequent check 'if (!ser)' was ineffective at >> > > >> catching a missing serialized_data, leading to unsafe dereferences later. >> > > >> >> > > >> Validate that args->serialized_data is non-zero before calling >> > > >> phys_to_virt(). >> > > >> >> > > >> Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd") >> > > >> Signed-off-by: Tarun Sahu >> > > >> --- >> > > >> mm/memfd_luo.c | 10 ++++++---- >> > > >> 1 file changed, 6 insertions(+), 4 deletions(-) >> > > >> >> > > >> diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c >> > > >> index 59de210bee5f..10f3983b0060 100644 >> > > >> --- a/mm/memfd_luo.c >> > > >> +++ b/mm/memfd_luo.c >> > > >> @@ -397,10 +397,11 @@ static void memfd_luo_finish(struct liveupdate_file_op_args *args) >> > > >> if (args->retrieve_status) >> > > >> return; >> > > >> >> > > >> - ser = phys_to_virt(args->serialized_data); >> > > >> - if (!ser) >> > > >> + if (!args->serialized_data) >> > > > >> > > > We really should make args->serialized_data a KHOSER_PTR >> > > >> > > Hmm, that would also be a good idea. I suppose then it would be a better >> > > to directly convert to using KHOSER_PTR() instead of this patch? >> > >> > Makes sense. >> >> I think we should systematically cover all phys_to_virt conversions >> and add KOSHER_PTR() , instead of an ad-hoc approach of adding it as we >> go. So, let's take this patch and do a series where we properly convert >> everything and provide guidance for others to use going forward. > > It's too late for this patch for -rc1. So let's systematically convert all > 4 or 5 direct phys_to_virt() conversions in the next cycle and be done with > it. > > We have enough time to make it by -rc2. I am already working on converitng them to use KHOSER_PTR. I have patch ready, Will send soon after some testing. ~Tarun > >> Pasha > > -- > Sincerely yours, > Mike.