Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1594975pxb; Mon, 12 Apr 2021 01:47:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPgmrNv5LUiqodS/UBWl1CmQpKaPinUDnNX0DGoHHSncBIvtZIhcZq1vCTV2wi7He3Y7zv X-Received: by 2002:a17:90b:784:: with SMTP id l4mr28190322pjz.90.1618217251750; Mon, 12 Apr 2021 01:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618217251; cv=none; d=google.com; s=arc-20160816; b=S+C3+d9eFuLyapERa2tEymHYZCJpLRTJeMFs80HW7+KnPt0TUZSu7TKj/bYolJ+VBl 4Bz+arXf/zsUXKpO2xxyjDgcYUjieKCE3n5D+qVoxuTlb+Gt/VCQySsYOv9G7VOsmRnD Tt6DJzw/NcWjE0HDhQwu/mhbfji6Aql4SRwYkb/Q/VXsUcyURwmJd6N78GTyLU+oodGE IouzqG8dHGmOKxHfHnSyHiZjhGm5Nk2CzbJfDsaqFWAO6e5OW49UVjowTCw1/JaDGYyK yJ16Wllc/BjL/BU65PxNFSKpoufT3HRr+/wvapjjYONaaQWfoQsZSjibYS+wd0CSWMEY nRTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dtzYct8hDd0TUTJeNPn+VU00CZc2TVVhEO/6lIGTE3k=; b=VjbQK8D1OKgtlfASZHUgkBWSNNYRtZ8fzCDGhX3fb+QBlcqqgDArLwZ4gx5kLYYD2l hSHJdC9nqAj3z2YyLTH2Op5SxYTSIMJQjyaIdrjVEdiG7G4ABfmcnd+N4EsUYqeMncwR DHG+9v3C0hHSl1SJestjv7EepwqSy3BqUVhsIRtkPWxLAYxCpNydtmt8zp/9OGRMy/Lh 63zVM43SscRVQr5D9U0CHjFWjX7FQ0cSOwh8Z3bXozG13zYjhyiig8Isplj6nESgruIA XEbttysZft1HwSrJ2tOyNT35NSOgaV/4UNAhjY3NYCy06+Snriq4d19Nc7rMJq+X6bwn lpGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PIdH2o4Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si12170493pgm.340.2021.04.12.01.47.20; Mon, 12 Apr 2021 01:47:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PIdH2o4Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237775AbhDLIpU (ORCPT + 99 others); Mon, 12 Apr 2021 04:45:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:36708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237660AbhDLIog (ORCPT ); Mon, 12 Apr 2021 04:44:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C1EE61246; Mon, 12 Apr 2021 08:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217058; bh=yesVKx5eIm8VpwVCsk4m8L6GiNrdiYjn0CcXdfHpZds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PIdH2o4Y5H/O40RMn7I5nf+quwPo1sd5e5C9nQiUvYbZ+2xeN9IzXEpi2DHUIbi18 KUebNs2+D2kwbgbpXws8bt4pDyv3RrncX5h7cgbtHQEw6FrSeuck7aTKkcZWpdWSbM WkWfnp9S6hUsfpGek3KAaReVLYCOJdRDAqRtw65k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+001516d86dbe88862cec@syzkaller.appspotmail.com, Phillip Potter , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.19 54/66] net: tun: set tun->dev->addr_len during TUNSETLINK processing Date: Mon, 12 Apr 2021 10:41:00 +0200 Message-Id: <20210412083959.874755461@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412083958.129944265@linuxfoundation.org> References: <20210412083958.129944265@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phillip Potter commit cca8ea3b05c972ffb5295367e6c544369b45fbdd upstream. When changing type with TUNSETLINK ioctl command, set tun->dev->addr_len to match the appropriate type, using new tun_get_addr_len utility function which returns appropriate address length for given type. Fixes a KMSAN-found uninit-value bug reported by syzbot at: https://syzkaller.appspot.com/bug?id=0766d38c656abeace60621896d705743aeefed51 Reported-by: syzbot+001516d86dbe88862cec@syzkaller.appspotmail.com Diagnosed-by: Eric Dumazet Signed-off-by: Phillip Potter Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/tun.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -77,6 +77,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -2864,6 +2872,45 @@ static int tun_set_ebpf(struct tun_struc return __tun_set_ebpf(tun, prog_p, prog); } +/* Return correct value for tun->dev->addr_len based on tun->dev->type. */ +static unsigned char tun_get_addr_len(unsigned short type) +{ + switch (type) { + case ARPHRD_IP6GRE: + case ARPHRD_TUNNEL6: + return sizeof(struct in6_addr); + case ARPHRD_IPGRE: + case ARPHRD_TUNNEL: + case ARPHRD_SIT: + return 4; + case ARPHRD_ETHER: + return ETH_ALEN; + case ARPHRD_IEEE802154: + case ARPHRD_IEEE802154_MONITOR: + return IEEE802154_EXTENDED_ADDR_LEN; + case ARPHRD_PHONET_PIPE: + case ARPHRD_PPP: + case ARPHRD_NONE: + return 0; + case ARPHRD_6LOWPAN: + return EUI64_ADDR_LEN; + case ARPHRD_FDDI: + return FDDI_K_ALEN; + case ARPHRD_HIPPI: + return HIPPI_ALEN; + case ARPHRD_IEEE802: + return FC_ALEN; + case ARPHRD_ROSE: + return ROSE_ADDR_LEN; + case ARPHRD_NETROM: + return AX25_ADDR_LEN; + case ARPHRD_LOCALTLK: + return LTALK_ALEN; + default: + return 0; + } +} + static long __tun_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg, int ifreq_len) { @@ -3018,6 +3065,7 @@ static long __tun_chr_ioctl(struct file ret = -EBUSY; } else { tun->dev->type = (int) arg; + tun->dev->addr_len = tun_get_addr_len(tun->dev->type); tun_debug(KERN_INFO, tun, "linktype set to %d\n", tun->dev->type); ret = 0;