Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp12111602ybi; Fri, 26 Jul 2019 05:01:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaqP26FQnp52C6xF1eUrOC4pPaLIQtw04JYNewN131QvCQ36lYVrVt0gmdfQqUxs5Mr1pb X-Received: by 2002:a62:26c1:: with SMTP id m184mr20965372pfm.200.1564142465889; Fri, 26 Jul 2019 05:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564142465; cv=none; d=google.com; s=arc-20160816; b=cN7blISd4FY7TTh58nbG3hhZko0jJC3ZCRkkRACTqjZd/PDwe/0E6UL3szhTZIJMhb VWiKFDB6/+koc0bR2udFKBE56ORUBPtjvp6r96RKlZvPRdv+hDl9vrbY6kE/+/NtVqGJ /ggItxGNEXFRFG33XuDFQxGd/zCdoipayv4ZIf/rEQs+gMRBw70Ad651TQiF2NbIdWev GWKNc2hShhPknTSk25/EnTqcev8N5kMc0yUgGKfzOUjPgh/Te+gw10i3PfFdiMfmVxPk UxRYszTcNPMSSRTxkXkxWnqkcBiHHYzzkSNpWqpN6JlRjzi3dYHjl7if7/USEszaw+kx yQJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2LG0AzeYCrP2HPh4ReaU07gb34Xc8BwShnIuQhHSCaA=; b=o2CAz89lBiAHd4R5Wz/TxwM1B/Mc/io5IMDeiYrCf3i+GlaBVwXl7zyG/erSOTgG4P bT6vC6JXoh3RvRzHgAbYsZb/O0odgTyPLO2fMFcLZG9lM7b0YJDYv1hkHbr+p0y6KGgf BBWBjZujJztQYwzih+5l4XbfR29WD8VyeXGIzhaH88uFmTh5KEe5S8HvywDtjDBEIyDQ ajXYEwsN1fp9bxLs+wBR5nJOWFd1IP5woruqzU36/ehjUp5fG7l3OYEvPHsXcIWYgTXW 1PffTG34vYxtEpIqHTUBpuRWmmNvdlJ0w8LxUtC7gOj774t9GhctPy4rJlnVYP9wW5l9 MngQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eJy4qywY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az12si17338462plb.5.2019.07.26.05.00.42; Fri, 26 Jul 2019 05:01:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eJy4qywY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726352AbfGZLpg (ORCPT + 99 others); Fri, 26 Jul 2019 07:45:36 -0400 Received: from mail-yb1-f195.google.com ([209.85.219.195]:38985 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726298AbfGZLpd (ORCPT ); Fri, 26 Jul 2019 07:45:33 -0400 Received: by mail-yb1-f195.google.com with SMTP id z128so16092831yba.6 for ; Fri, 26 Jul 2019 04:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2LG0AzeYCrP2HPh4ReaU07gb34Xc8BwShnIuQhHSCaA=; b=eJy4qywY76PYX6Wq+0zlTbLlEE+um6eGdLbCQ4a9LkeyyavV0kCo1CzQ1MfPBYJRHx mKRuwgeGGdIj0sI0lJuhlCTGJhzBlwxAw8ouHd+LhwuTOL66GBFLIypxORhqhGAhgFwJ yIvoLtiCqbodpU3TEp26OSbXbBawiJr76Ul80QWH/Jlx8mbbIE2AwyLn4CzxpOiInTx4 rMDYMjB8Mw7yi7UqypknsRP35NtBUQHseHV4y43s931zqUwIPBQbX+UQblxDYV3xivMA /lnWdjX2Wc0qBe9HTFcYuqET4O4jPnwNLYf3tMUBBNUmkmUOibQ3JMvBCaBkoIWtY5iI OVjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2LG0AzeYCrP2HPh4ReaU07gb34Xc8BwShnIuQhHSCaA=; b=aSYJTOsOST8tOspc9KMC5mrz3+tLw371r4hqryi5Ya7xW4rzCB+lsDsPNClnZWCwmb ULQjTYZOoF37cugML85jhunJVxV2fqoEJKktDFSI0JYAmTG90g8K8Y4Ai2okkixMierM v5y3mXQazEKZV9yiwFqGAorTkJEtQOR8r0D2g5RestPhZCRXMbp6KBrBFB6g2aRDuigu aZo2EjFIX4O8ZXDAUdFjyh4EEPnwpo6eHAO06wVkkuxEKqFsIALh+8JubJDsWvd2PRbT 5/r8Lv7ZV0lcLYCky01OGeo8p66lOfZNbQeE8DxzQgLxzchdo5g+D8HtKpjYnMY5d7Ba 10PA== X-Gm-Message-State: APjAAAVxrPaNe+uA667EHLLEd1L/kz3XDVNftrZMJDPV+0gyERx21myg xd4IEolloGY1BZJQHWm9k8N1SNFT X-Received: by 2002:a25:324b:: with SMTP id y72mr51809197yby.146.1564141532194; Fri, 26 Jul 2019 04:45:32 -0700 (PDT) Received: from mail-yw1-f53.google.com (mail-yw1-f53.google.com. [209.85.161.53]) by smtp.gmail.com with ESMTPSA id q83sm12796555ywq.88.2019.07.26.04.45.30 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jul 2019 04:45:31 -0700 (PDT) Received: by mail-yw1-f53.google.com with SMTP id i138so20253200ywg.8 for ; Fri, 26 Jul 2019 04:45:30 -0700 (PDT) X-Received: by 2002:a0d:c301:: with SMTP id f1mr53998273ywd.494.1564141530408; Fri, 26 Jul 2019 04:45:30 -0700 (PDT) MIME-Version: 1.0 References: <20190726080307.4414-1-baijiaju1990@gmail.com> In-Reply-To: <20190726080307.4414-1-baijiaju1990@gmail.com> From: Willem de Bruijn Date: Fri, 26 Jul 2019 07:44:54 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] net: ipv6: Fix a possible null-pointer dereference in ip6_xmit() To: Jia-Ju Bai Cc: David Miller , Alexey Kuznetsov , Hideaki YOSHIFUJI , Network Development , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 26, 2019 at 4:03 AM Jia-Ju Bai wrote: > > In ip6_xmit(), there is an if statement on line 245 to check whether > np is NULL: > if (np) > > When np is NULL, it is used on line 251: > ip6_autoflowlabel(net, np) > if (!np->autoflowlabel_set) > > Thus, a possible null-pointer dereference may occur. > > To fix this bug, np is checked before calling > ip6_autoflowlabel(net,np). > > This bug is found by a static analysis tool STCheck written by us. > > Signed-off-by: Jia-Ju Bai > --- > net/ipv6/ip6_output.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c > index 8e49fd62eea9..07db5ab6e970 100644 > --- a/net/ipv6/ip6_output.c > +++ b/net/ipv6/ip6_output.c > @@ -247,8 +247,10 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, > if (hlimit < 0) > hlimit = ip6_dst_hoplimit(dst); > > - ip6_flow_hdr(hdr, tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel, > - ip6_autoflowlabel(net, np), fl6)); > + if (np) { > + ip6_flow_hdr(hdr, tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel, > + ip6_autoflowlabel(net, np), fl6)); > + } I don't know when np can be NULL in ip6_xmit. But if so, must still setup the ipv6 header. A more narrow change would be in ip6_autoflowlabel - if (!np->autoflowlabel_set) + if (!np || !np->autoflowlabel_set)