Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp646100ybh; Tue, 10 Mar 2020 05:47:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsaWZDTIP9+oKi4E+YJ/WQx2SStbzLeXp0UI25fQiUSgCpr8Og707xigbfkZd9wS5NzW3y2 X-Received: by 2002:a05:6830:1d95:: with SMTP id y21mr15944029oti.90.1583844468083; Tue, 10 Mar 2020 05:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583844468; cv=none; d=google.com; s=arc-20160816; b=feUhDGQx2hX1pTUJJ+/8nGjLLhhxVkFESQbj1UzDwvvewvrU49A1oBCv5WUMs7+UTY TPQfHG1dRdmmuv1Lj0GZfyyF8xTLrtvqZBW6YXHjgo0lQS5Zw5URkzaYWsyLqN3E/cTt HLQB2gSUsXf0zPKU06qFf/o2ofZ7Ak5kW1CQuKfkD1bo0Y9GlH/vQ0xQuodjI9nsYHWE jIqaraYsZe5bIp0jPB5JH1JkQ8TDcCyd9kO1FlHuykJgSKhkh8VrAuLi4m2sx1+Mu7hs q4VobhY61a/xRAQ89ajaj3mJknqN+Q6tw+5a98U6eZ58YBN83z3eIdqhqR1W3YVFF0Vv xHnw== 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=oFraT1DvLU7K+QRGpwcamZXIjbHLUMnRT/7OJctX2VQ=; b=ust1+rHriMiJWh7M9iqqRDbeau9XDSwG8nH7wtRo/HGZFKo/paFw9fbPmRhhN9HOIT V483FjfXrMTpffhLmBhke5ZJDKuFwgbPtlTm9oiMD9zM0o3FFplw3N+OnDxe872/qi42 liV7yq39otVBMDN+cfAsmrC8/tZ5hOrY0YrSAL8ac2WYcrxz2LHX98VX9OD9km8uOD9y vij++mqrJl+bxuh3AcPJzgh/g0tGGlMX98Z/L7hzoXq/UhXV6AceZUyPBAscBoTV8b43 ZFcxyav/VBPM8YUeJ2pVaXUEdaldYOLPDLKz1qwSKk0hjNyoAdhkxQKxdjqP6/YlTx9t aVPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="KAOHqr/B"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i19si5655662oie.131.2020.03.10.05.47.36; Tue, 10 Mar 2020 05:47:48 -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=@kernel.org header.s=default header.b="KAOHqr/B"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727316AbgCJMpx (ORCPT + 99 others); Tue, 10 Mar 2020 08:45:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:48696 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbgCJMpv (ORCPT ); Tue, 10 Mar 2020 08:45:51 -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 C6B0D2467D; Tue, 10 Mar 2020 12:45:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844351; bh=NisVW/p2wf8rpwpiYJMb0ShWUKL331EHXrmVqlbQlhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KAOHqr/BIQT84CGzWDRUXI74KgG/jWJAjqWIqH5VbryOPwOA9GFMePsR1tfTanXn6 26J7O5Sp+Fsy01vLWVbuNQOLmE42rODaKP4Z2ttl0hSZMjpjaUmHZ1DcQ7ER1JuRe4 TonpoaOUBu20CociAoO/HlbMYNWl7RgLxsRxc+Kk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f2a62d07a5198c819c7b@syzkaller.appspotmail.com, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , "Michael S. Tsirkin" , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 50/88] vhost: Check docket sk_family instead of call getname Date: Tue, 10 Mar 2020 13:38:58 +0100 Message-Id: <20200310123618.551780685@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123606.543939933@linuxfoundation.org> References: <20200310123606.543939933@linuxfoundation.org> User-Agent: quilt/0.66 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: Eugenio Pérez [ Upstream commit 42d84c8490f9f0931786f1623191fcab397c3d64 ] Doing so, we save one call to get data we already have in the struct. Also, since there is no guarantee that getname use sockaddr_ll parameter beyond its size, we add a little bit of security here. It should do not do beyond MAX_ADDR_LEN, but syzbot found that ax25_getname writes more (72 bytes, the size of full_sockaddr_ax25, versus 20 + 32 bytes of sockaddr_ll + MAX_ADDR_LEN in syzbot repro). Fixes: 3a4d5c94e9593 ("vhost_net: a kernel-level virtio server") Reported-by: syzbot+f2a62d07a5198c819c7b@syzkaller.appspotmail.com Signed-off-by: Eugenio Pérez Acked-by: Michael S. Tsirkin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/vhost/net.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index dd8798bf88e7c..861f43f8f9cea 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -914,11 +914,7 @@ static int vhost_net_release(struct inode *inode, struct file *f) static struct socket *get_raw_socket(int fd) { - struct { - struct sockaddr_ll sa; - char buf[MAX_ADDR_LEN]; - } uaddr; - int uaddr_len = sizeof uaddr, r; + int r; struct socket *sock = sockfd_lookup(fd, &r); if (!sock) @@ -930,12 +926,7 @@ static struct socket *get_raw_socket(int fd) goto err; } - r = sock->ops->getname(sock, (struct sockaddr *)&uaddr.sa, - &uaddr_len, 0); - if (r) - goto err; - - if (uaddr.sa.sll_family != AF_PACKET) { + if (sock->sk->sk_family != AF_PACKET) { r = -EPFNOSUPPORT; goto err; } -- 2.20.1