From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 068DF357D0E for ; Thu, 11 Jun 2026 13:37:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781185037; cv=none; b=CMeaKl2vQ+s33tnJslLo3ipaptnVVswqSg0gH8SBUVqomuDK6LcUd7XL1SjVmERTrUyueMp9aXEwZLOKv9cBvyu92ePY0ROLT9qxseFAb9XTn7SVykcFBi1YQg0XF5RU+wa5CroSiHLdUQdavLeLz8CFqwV+qyjTLryyh3SebXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781185037; c=relaxed/simple; bh=IVhi1/Km6G6xTFUMpnXedkuEW8XiKyJK9pT3paF5cXg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=WL9Sun7QxhEBk/VXokG08gil9MidsiMP4RKljwZQwk78zYffAlT9OxFWSd/WAG62z3Qahm6uKV9LbbQ3CwqnVdRO6JsyJCFuBxvr4ZVx1HC2tWshSq0LGwqLNKW3kMjtaVpCfv40sx+fXTuRrSiZ7Hjqhz7DJRKVzFviUmowvkw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UmAJp2HG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UmAJp2HG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 463FB1F00893; Thu, 11 Jun 2026 13:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1781185035; bh=OontUb7qE56W5Wue/M2LU8FmpW0BHV0EyXoJjTMFI3Y=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=UmAJp2HGw6a1cxu8Z7qUN33jlTIG2j+zWU8WRaBYMPD0e82ko/eZ36AgAOa43kY/h lxlrudp9simk7JoBMca54NyZEiKzJWI3xHq2I1kMIbJ1GduGALBQqbCBcYKGWYTFml 5vfTpJMEs/Ewmp3fN/cMWDpJaVYBCErmVSoa/nVd3BNHzL1DSVVHXG8CYdXTe5g+EE xDYke9gzTLyp1NWBse1zzjPaNGj6xpmesgfWQ6pdUmfK2zOnhfdz4GuStr5vUNRqfT EAl2lV0KWC1COJwOyO0SXjG50HaGTpdkfNeGrd4M9vMiPC4pKJCOBSsVBpQaOqYjgK 0CNto2tHZMgOA== From: Pratyush Yadav To: Mike Rapoport Cc: Tarun Sahu , Pasha Tatashin , Pratyush Yadav , Andrew Morton , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/memfd_luo: validate serialized_data before conversion In-Reply-To: (Mike Rapoport's message of "Thu, 11 Jun 2026 15:40:03 +0300") References: Date: Thu, 11 Jun 2026 15:37:12 +0200 Message-ID: <2vxzmrx1qjuf.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain 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? > >> return; >> >> + ser = phys_to_virt(args->serialized_data); >> + >> if (ser->nr_folios) { >> folios_ser = kho_restore_vmalloc(&ser->folios); >> if (!folios_ser) >> @@ -522,10 +523,11 @@ static int memfd_luo_retrieve(struct liveupdate_file_op_args *args) >> struct file *file; >> int err; >> >> - ser = phys_to_virt(args->serialized_data); >> - if (!ser) >> + if (!args->serialized_data) >> return -EINVAL; >> >> + ser = phys_to_virt(args->serialized_data); >> + >> /* Make sure the file only has seals supported by this version. */ >> if (ser->seals & ~MEMFD_LUO_ALL_SEALS) { >> err = -EOPNOTSUPP; >> >> base-commit: 9716c086c8e8b141d35aa61f2e96a2e83de212a7 >> -- >> 2.54.0.1099.g489fc7bff1-goog >> -- Regards, Pratyush Yadav