From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A30CC28EBD for ; Sun, 9 Jun 2019 17:18:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEC7820652 for ; Sun, 9 Jun 2019 17:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560100705; bh=TCF4iOKzqxIevE/NV8uMl5PmPulEYK8lW6EYnBVeMdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dL4tAwebiauq2dpuOQJPMOrUlY55fV25w3vS5GcARGJr6Zw4yMLGI7oNmQGM+U8Ms zuQREpGOLVKiZ7c/4vg6JTjN9NjhyIVHlhcLUfdGTkvi6UOaYK2IzGaFGmybfzbgaf +BD7wVF09yV/xEbqd2TdY2sUO5Sbo0i3K0FEeL6o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730633AbfFIRSY (ORCPT ); Sun, 9 Jun 2019 13:18:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:50136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731690AbfFIQuT (ORCPT ); Sun, 9 Jun 2019 12:50:19 -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 6DC142070B; Sun, 9 Jun 2019 16:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099018; bh=TCF4iOKzqxIevE/NV8uMl5PmPulEYK8lW6EYnBVeMdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wA1IwhbvtoMWds8Pinq1oa0zdz89UpDTog2I6VZ9uNiK0yQrkfj6yR7FLYbGW9o5C Wfj+thaNXANlfjr8e5593Swk/BjKo77ymv0wqUVbvcUo4mj8L+MbEsIzb96VUx/sMF 76NaO9LBAOsb4viFbfQBNj5C9dOK7pYi8d8C+9Yo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Olivier Matz , Nicolas Dichtel , "David S. Miller" Subject: [PATCH 4.14 07/35] ipv6: fix EFAULT on sendto with icmpv6 and hdrincl Date: Sun, 9 Jun 2019 18:42:13 +0200 Message-Id: <20190609164125.944252126@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164125.377368385@linuxfoundation.org> References: <20190609164125.377368385@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Olivier Matz [ Upstream commit b9aa52c4cb457e7416cc0c95f475e72ef4a61336 ] The following code returns EFAULT (Bad address): s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); setsockopt(s, SOL_IPV6, IPV6_HDRINCL, 1); sendto(ipv6_icmp6_packet, addr); /* returns -1, errno = EFAULT */ The IPv4 equivalent code works. A workaround is to use IPPROTO_RAW instead of IPPROTO_ICMPV6. The failure happens because 2 bytes are eaten from the msghdr by rawv6_probe_proto_opt() starting from commit 19e3c66b52ca ("ipv6 equivalent of "ipv4: Avoid reading user iov twice after raw_probe_proto_opt""), but at that time it was not a problem because IPV6_HDRINCL was not yet introduced. Only eat these 2 bytes if hdrincl == 0. Fixes: 715f504b1189 ("ipv6: add IPV6_HDRINCL option for raw sockets") Signed-off-by: Olivier Matz Acked-by: Nicolas Dichtel Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv6/raw.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -889,11 +889,14 @@ static int rawv6_sendmsg(struct sock *sk opt = ipv6_fixup_options(&opt_space, opt); fl6.flowi6_proto = proto; - rfv.msg = msg; - rfv.hlen = 0; - err = rawv6_probe_proto_opt(&rfv, &fl6); - if (err) - goto out; + + if (!hdrincl) { + rfv.msg = msg; + rfv.hlen = 0; + err = rawv6_probe_proto_opt(&rfv, &fl6); + if (err) + goto out; + } if (!ipv6_addr_any(daddr)) fl6.daddr = *daddr;