From patchwork Wed Oct 18 22:49:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1851344 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S9mJ52MQcz1ypX for ; Thu, 19 Oct 2023 09:49:41 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qtFM3-00057a-An; Wed, 18 Oct 2023 22:49:31 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qtFLs-00056F-H1 for kernel-team@lists.ubuntu.com; Wed, 18 Oct 2023 22:49:20 +0000 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 712853F20F for ; Wed, 18 Oct 2023 22:49:18 +0000 (UTC) Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4196a386347so84816841cf.1 for ; Wed, 18 Oct 2023 15:49:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697669356; x=1698274156; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9SvwUNkJOunMVJVaP5syPBaYH1LCFnMgyghxzTedlrU=; b=ErGmGWX02iJx5Z2RSRKtZ3NG9b7xOM3yNgNfdkv6vWij2ByC/tzdD8RlBMH56C8P1a q9b2O97cYqongOXQHJu0L5kkJ/gJawgMAH80Pidd1CxyavuXderSVc7O1DVV2784fYJZ 9VwVihr6pGQmpArNp7hYHN9PB44Fq/6sJJMMgoCB5QDOv/cfvdLilD30eh4wctOKQ0j7 Tryg4fAf5lmepZGNGYC3rqtSU2e6L5M6hjfBctbsHsSX3128vXth9VEzr/dkjZOxCXG6 jjF45UUIPDMF5pYV5jog4dDaDK1Kxd9GbNrYvGDTIYed/mYXwx/Wf/nJVF13IjodczAt 9V2Q== X-Gm-Message-State: AOJu0YwMIQt1akWrGfkFqIzF1P+in2zFDZv5LIBrrGC0A738WFWEEzvD AI75RL9UyRAL27e0bOdXj5J2TksVg74IO5Q4y8qJHywaubyGdZHZmNDqFB0MbjyJ8BlzJ1Q+BSH QXqs/BJZKKXfD2r6J0K3ZxoRfk9ewzD9e8lKBdEINcB53fVy5YA== X-Received: by 2002:a05:622a:1c5:b0:419:5162:5e04 with SMTP id t5-20020a05622a01c500b0041951625e04mr631298qtw.43.1697669356497; Wed, 18 Oct 2023 15:49:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9zamVyTRt40DY/TMErlpfBPSu692bRqEZ1xQP1pDD2Z+mlEAtiRB5EYQBtfso6UGy46f4Xw== X-Received: by 2002:a05:622a:1c5:b0:419:5162:5e04 with SMTP id t5-20020a05622a01c500b0041951625e04mr631291qtw.43.1697669356248; Wed, 18 Oct 2023 15:49:16 -0700 (PDT) Received: from cache-ubuntu.hsd1.nj.comcast.net ([2601:86:200:98b0:f2f9:d22:a77f:11d]) by smtp.gmail.com with ESMTPSA id f29-20020ac86edd000000b0041b3deef647sm296729qtv.8.2023.10.18.15.49.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 15:49:15 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [SRU][F/J/L][PATCH 1/1] ipv4: fix null-deref in ipv4_link_failure Date: Wed, 18 Oct 2023 18:49:13 -0400 Message-Id: <20231018224913.62418-2-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231018224913.62418-1-yuxuan.luo@canonical.com> References: <20231018224913.62418-1-yuxuan.luo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Kyle Zeng Currently, we assume the skb is associated with a device before calling __ip_options_compile, which is not always the case if it is re-routed by ipvs. When skb->dev is NULL, dev_net(skb->dev) will become null-dereference. This patch adds a check for the edge case and switch to use the net_device from the rtable when skb->dev is NULL. Fixes: ed0de45a1008 ("ipv4: recompile ip options in ipv4_link_failure") Suggested-by: David Ahern Signed-off-by: Kyle Zeng Cc: Stephen Suryaputra Cc: Vadim Fedorenko Reviewed-by: David Ahern Signed-off-by: David S. Miller (cherry picked from commit 0113d9c9d1ccc07f5a3710dac4aa24b6d711278c) CVE-2023-42754 Signed-off-by: Yuxuan Luo --- net/ipv4/route.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 435def2c74b59..34c5996d41c31 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1221,6 +1221,7 @@ static struct dst_entry *ipv4_dst_check(struct dst_entry *dst, u32 cookie) static void ipv4_send_dest_unreach(struct sk_buff *skb) { + struct net_device *dev; struct ip_options opt; int res; @@ -1238,7 +1239,8 @@ static void ipv4_send_dest_unreach(struct sk_buff *skb) opt.optlen = ip_hdr(skb)->ihl * 4 - sizeof(struct iphdr); rcu_read_lock(); - res = __ip_options_compile(dev_net(skb->dev), &opt, skb, NULL); + dev = skb->dev ? skb->dev : skb_rtable(skb)->dst.dev; + res = __ip_options_compile(dev_net(dev), &opt, skb, NULL); rcu_read_unlock(); if (res)