Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp693814ybg; Mon, 1 Jun 2020 11:52:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFNSxW4ZJmrSglN9hJ2efzDDiQ4Nx5tQiGFqDtqUa+DdGJcpb7s3VOp1ZnHwL6UqdQYEPr X-Received: by 2002:a50:d7d1:: with SMTP id m17mr23865351edj.126.1591037535558; Mon, 01 Jun 2020 11:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591037535; cv=none; d=google.com; s=arc-20160816; b=DBilmINMAj7SmvTVcynbDDD/+v3QQYZW19lxL+HcFgMXGvDIOtduzaA0zWvNf1veVY 9rDIPT2nagjJhsXirT3EO8q9E8smjqQ4iJm6YU44HzkopYW4wkw0U4LpnpM+YwAi15t+ e/8Hs0oHEUKq1yCJv/SwjlJhPPPaYHlW9peVd29DNjIB9UPX2EIAqzPIAxsd+DOwMp3q Yp1Gf9nJlhI0nVrIp7IQBk7TW2vOe2jzWeaPwvOMA8IwHPgKiBAg2jvvOpilZpypqtmn Y8huSSp8LIL3rI6C2qFeYr7wCpCxXk2EPSBXt+duDUixtD1B+xbYq4d+I+l3emfW7uGF DYBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/SNQEUIZ8oxtLgf7KyzWnFQBxX2L07lwtnJmdPBGuH8=; b=02tWwaBFhhuSICgW5WCEtgubPwPuFJFSyGwXBfzjytnhvRZekqQOCTFkcLyntkcDUq lQ0dnhrWNNmIUdMFBGyDxWUE7aPJ1+KZXdZD5EtTFHxYGQwXfSxpsHBHucc71laTylnJ qZToAZES9IiRSAbr8JRHxrYViVYs9fh+fBdjaRvXvtsKobyj05vkS+nZfzQO8SmQ1n4w 2sXft/C7bpkb6q+77aKq0roKCDKOTi0BO+hlv5dT6jEYFJOvGbRlUYW3gjiN0BfDkRSS PGk+nAnksUURp4etdG35TawH4cV9xJNKocxr2gIl6+j3rFJ38YC5nqwwPBuhu9kzfZCP 6C9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CbMX4CoI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si135582edr.239.2020.06.01.11.51.51; Mon, 01 Jun 2020 11:52:15 -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=@kernel.org header.s=default header.b=CbMX4CoI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730442AbgFASuL (ORCPT + 99 others); Mon, 1 Jun 2020 14:50:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730435AbgFASGS (ORCPT ); Mon, 1 Jun 2020 14:06:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BA53B206E2; Mon, 1 Jun 2020 18:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591034777; bh=zZkMrV8sfL+xm3WaOiI2ZiFlxFU4FE6jKQUP2VeQ53o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbMX4CoIe8eczDfe8M//B3dxdgPXAZOLRY+TiqBtbUKjbQ1072caaxR7ZFOWRV1xD sPF53LCp6EI+J3T620S7OgFdG/i6hTHBNukJ8wliyt+XbDHf7kTB3ivyg3xZswS1L6 awFgQU0820KINuvL0XOrCCbFMYwm/Z0n1lOgr8vc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , "David S. Miller" Subject: [PATCH 5.4 001/142] ax25: fix setsockopt(SO_BINDTODEVICE) Date: Mon, 1 Jun 2020 19:52:39 +0200 Message-Id: <20200601174038.146844345@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 687775cec056b38a4c8f3291e0dd7a9145f7b667 ] syzbot was able to trigger this trace [1], probably by using a zero optlen. While we are at it, cap optlen to IFNAMSIZ - 1 instead of IFNAMSIZ. [1] BUG: KMSAN: uninit-value in strnlen+0xf9/0x170 lib/string.c:569 CPU: 0 PID: 8807 Comm: syz-executor483 Not tainted 5.7.0-rc4-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x1c9/0x220 lib/dump_stack.c:118 kmsan_report+0xf7/0x1e0 mm/kmsan/kmsan_report.c:121 __msan_warning+0x58/0xa0 mm/kmsan/kmsan_instr.c:215 strnlen+0xf9/0x170 lib/string.c:569 dev_name_hash net/core/dev.c:207 [inline] netdev_name_node_lookup net/core/dev.c:277 [inline] __dev_get_by_name+0x75/0x2b0 net/core/dev.c:778 ax25_setsockopt+0xfa3/0x1170 net/ax25/af_ax25.c:654 __compat_sys_setsockopt+0x4ed/0x910 net/compat.c:403 __do_compat_sys_setsockopt net/compat.c:413 [inline] __se_compat_sys_setsockopt+0xdd/0x100 net/compat.c:410 __ia32_compat_sys_setsockopt+0x62/0x80 net/compat.c:410 do_syscall_32_irqs_on arch/x86/entry/common.c:339 [inline] do_fast_syscall_32+0x3bf/0x6d0 arch/x86/entry/common.c:398 entry_SYSENTER_compat+0x68/0x77 arch/x86/entry/entry_64_compat.S:139 RIP: 0023:0xf7f57dd9 Code: 90 e8 0b 00 00 00 f3 90 0f ae e8 eb f9 8d 74 26 00 89 3c 24 c3 90 90 90 90 90 90 90 90 90 90 90 90 51 52 55 89 e5 0f 34 cd 80 <5d> 5a 59 c3 90 90 90 90 eb 0d 90 90 90 90 90 90 90 90 90 90 90 90 RSP: 002b:00000000ffae8c1c EFLAGS: 00000217 ORIG_RAX: 000000000000016e RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000000101 RDX: 0000000000000019 RSI: 0000000020000000 RDI: 0000000000000004 RBP: 0000000000000012 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 Local variable ----devname@ax25_setsockopt created at: ax25_setsockopt+0xe6/0x1170 net/ax25/af_ax25.c:536 ax25_setsockopt+0xe6/0x1170 net/ax25/af_ax25.c:536 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reported-by: syzbot Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ax25/af_ax25.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -635,8 +635,10 @@ static int ax25_setsockopt(struct socket break; case SO_BINDTODEVICE: - if (optlen > IFNAMSIZ) - optlen = IFNAMSIZ; + if (optlen > IFNAMSIZ - 1) + optlen = IFNAMSIZ - 1; + + memset(devname, 0, sizeof(devname)); if (copy_from_user(devname, optval, optlen)) { res = -EFAULT;