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 533FA40D577 for ; Sun, 28 Jun 2026 00:11:19 +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=1782605480; cv=none; b=oWRQqT3Z0/MHAPQFPdCczSGS3Zd/RQQUC9xsnxj7USe0e5lWd3pAva8u33CAYg1MnrGvjmiwYVNMJt1mQ2BgN4E0KwWqIEXjGT31IDkE9SWApdGK5vsu8HEyh+BvoIvcEWKBKPwiJjvocxcButLWbRosJECWEBIXl8JfeiT2MSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782605480; c=relaxed/simple; bh=+DvRn066m9VhgttUB8kWCbbvUHkMNec7QLp7DPSpu/M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Vqxe5zy4V+dyElo5RUhbl96oCIrYVyMDHt66aXo/vbY8xCkEFrWCkGJFXf9r8W8zHA90dCDecu0dm9w27w4o/FdHXYtPItiq0HbFsQnJLQ+87GHpObI+bkFH79yo0NQ6jxgIL0xkKVEmi7dni9P2itWn0/PwL1bbPfXN/y6+WdI= 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=SV3Qkub9; 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="SV3Qkub9" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-695bbac451bso2487593a12.1 for ; Sat, 27 Jun 2026 17:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782605478; x=1783210278; 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=9wo+YX/Ag7ncd7bf256KRZ5DnnahmErnNNobKR7tPZM=; b=SV3Qkub9Yk42zF2e4wNHJYqsbt52ysErm3anUUYJwl1883itBRFvajErYJ3QUCARtu E+w0+uWpXUKcjDQeckOQLEJj3QuBnC061tDDuaV2MjFOePhfSjtF9BQYlbsQVeTxX+Ev vRbPxd6AylL1W+Z6fzkOibRuhsaqC3Lpewns8Bxmu0SNHcJAfb3Z5plFpg7o4iRlwn2G LlNLi7xzIICVmC1GEwsLBWS1Ex1/yS2fafxABMShr/kYjBAYNMN/zqSpEZfSk0+EyzAR N4hOYj2IBvTA/4BpKX6lkYNnmmYPKuOB7KkyxPtID5AorHOz98eMINw1ASeBleHaIplM Leig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782605478; x=1783210278; 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=9wo+YX/Ag7ncd7bf256KRZ5DnnahmErnNNobKR7tPZM=; b=X8Zw5G/JNbKmvThQZG5lZmocL4q8aU5XzWvv5Ht09iX9e4syHyWjJeXuCC6O2qnsqu Vvz8ukyo2K2zjADWwNGhaLDZlbUkBCQvRG4vEvw0udWvtz4/SkixdjERe4aTA0pHpYnH xFirN1zSPNhjCQtgwDFfXC9RLfJvYC6tf1WFN/hvw8EBjE+12ckiRd8kRo/0zlqp81GQ U9dLAH2kRKMIYKYCI5kemckGlwo27KkaBChV+4Eb+uRzpKp9vWwYYCZY/BNh7SIBpun9 Dy1Lo30sWh1t7P+dCWqJky3c6+vcQy6OJB9enFXvR8RJosa43HlGCizcrX7zCtwAbuP+ C69g== X-Forwarded-Encrypted: i=1; AHgh+RpzdHwAN1SdSZclHVsDmIA18lQmEsusviiV5TtXHLGLLX5DMea5rF4WFEbNuzxJvXYOs1jEyBfZhxQLG8o=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1KVECSm3zg5Urdr+KiZtkFitgs65bUQx7eNc54pqYrJ0RzeFM 4SEBVuGRHOi0ZYiJW6kb0saShh8uIhqMX0B73ZCugy3GfH5RHlhvZXoNmviySxEWpWELsjjkT2V piQnF8H9Or7rt8sNfWA== X-Received: from edxb10.prod.google.com ([2002:a05:6402:2ca:b0:698:3b14:4ab9]) (user=tarunsahu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:510a:b0:697:de29:c802 with SMTP id 4fb4d7f45d1cf-69810ab88f9mr4353570a12.18.1782605477536; Sat, 27 Jun 2026 17:11:17 -0700 (PDT) Date: Sun, 28 Jun 2026 00:11:12 +0000 In-Reply-To: <20260628001114.1869564-1-tarunsahu@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260628001114.1869564-1-tarunsahu@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260628001114.1869564-2-tarunsahu@google.com> Subject: [PATCH v6 1/3] mm/memfd_luo: validate serialized_data before conversion From: Tarun Sahu To: Pasha Tatashin , Pratyush Yadav , Andrew Morton , linux-mm@kvack.org, Mike Rapoport , Alexander Graf , skhawaja@google.com Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Tarun Sahu Content-Type: text/plain; charset="UTF-8" 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 Reviewed-by: Pratyush Yadav (Google) Reviewed-by: Pasha Tatashin --- 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) 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; -- 2.55.0.rc0.799.gd6f94ed593-goog