Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2064318pxb; Mon, 12 Apr 2021 13:22:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQFYZz16W3MRj2zI5XWcNiNCPMZnqMQWCnkaMBIspINr5oYj7hdRvr1Ro+Yl+GgIuih++P X-Received: by 2002:a17:906:3544:: with SMTP id s4mr29459749eja.73.1618258975803; Mon, 12 Apr 2021 13:22:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618258975; cv=none; d=google.com; s=arc-20160816; b=N33VJchYDmdwdXw5ld61ZA3V5HnSIGTBSz2Qp6TLzeGk3GMIdNLc45iotQ8yCTskCO TK+3cXSlqopr6E0X7VucseJlz4YdhnbE9BV+bYkQYlv1Ms+8cp4GgpYGK3fjGr68sGNr Z0gjN2oi50qLD3t/aTsLyqIVS4udilszzsALEk/Wlw1M4eykcEshGz747CrymOHQ3Eup BCyE7clKIWk5UYC9bEKaNGqxK+QAhuXaN8p0n/RHAsKxXXME1FtDpcr35u7NDNeRxuPm OGjzWR1lDXl/sSD033LMm+mdkEBcCB0wnmPZQctEsTbv5szFnA5zLI2K6Mr5Sqgub8uZ tAVQ== 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=PnuSGjjpJG3rLOYh6TnVlWk+xODbqOSBXQh/58odsis=; b=jQiShJITLqAMbLNulAQHTQw1HeB8jEIgW2u36Ah56v+MRTSZ9zLgBeLvlCUoyC1eOL hDtLCloT19jE4oEwv0rfFKRYDW2BzGCipZFjOc4Yp47itGtxwNMJd8Ne2pS+yIjYyMbX CA/iNJwU9AcDUxzHQcE95CJ9cIEI7bUDDn3E5SFCEKWe1h5GRuiOH5diW17wj3L+4Mum fNvtQT8IsXCqAMDQ6FCelVSyOB38/k/oeI4GfG/gVavbariAbN0CWOWJWYVdPxbReweM kQwcgbTOooPy7GkNvr5L2XS/635TAc60KR0Uo8PF9guBmBDMG69V/JAgHECSzDBPOg0A xPyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dlFsphb0; 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 m13si8606189edc.258.2021.04.12.13.22.31; Mon, 12 Apr 2021 13:22:55 -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=dlFsphb0; 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 S238800AbhDLI5A (ORCPT + 99 others); Mon, 12 Apr 2021 04:57:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:39664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238493AbhDLIt6 (ORCPT ); Mon, 12 Apr 2021 04:49:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1135B61284; Mon, 12 Apr 2021 08:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618217363; bh=M6zoCmloHiMby+OTW7nWdfbUSdAitXLRl7zKZ/4xdtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dlFsphb0xPCR8Xzhmxb4YZDqQ9I19yOhS1UtldVNFO2aFtrIwKIiyn2Xj6nQXdEYH 5GiSqxESTL5jqydmWo7V8NzO2Jd5+gZYvb4vUTJZeamr9Purroa2osk7yty++5FMm6 yZMp2UqmUKC2ZdfMmWhRRyXmQVwxBLyx7Jaw1Ogc= 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 5.4 099/111] net: tun: set tun->dev->addr_len during TUNSETLINK processing Date: Mon, 12 Apr 2021 10:41:17 +0200 Message-Id: <20210412084007.548722441@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210412084004.200986670@linuxfoundation.org> References: <20210412084004.200986670@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 @@ -68,6 +68,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -3043,6 +3051,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) { @@ -3198,6 +3245,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;