Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp27724imm; Thu, 10 May 2018 14:50:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqfpNTWL6qMd4CGXyx3rl+evOobb3c4Soc5xNj1VLEPpL1c+1VupZ5jX7P5nNyz1AzlXcQ2 X-Received: by 2002:a17:902:7487:: with SMTP id h7-v6mr2838186pll.154.1525989026523; Thu, 10 May 2018 14:50:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525989026; cv=none; d=google.com; s=arc-20160816; b=X2s0ZniZ1xXiQLM1Np3v4PPt21IDXnW1f0aSgnBEZ1WsMdmj5k4RZL+InkjJlI7qoV ny2dOHtFDUrRSRTwudW30BDmwv/yH5FabPyVtzBe5z8BGMdPkltmceG+/Ff/g7zfEMX3 /0Dc8NbMIRWZaBGxY8xRjC2ctd02iRC/pTJAD3BQAySRVAfQnM9a6dDyCwKlvOqyZGiz pSJ6AXLYYAq68XSoBiA0IsFv0hA5Pwvi0jcbecJt8cjhEALh7oISREJEjW6t3OFU54an XGnFC/rrfOvJmFMGQYroRvKBMlaxOUVbFUAFsNrjy4wafNX/+J0KndMZWbQm9OlyO/we MufQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=DSFWYJzFM6jJ60Yq/XuiwoRm/dSecebxbD5Jpc9pygw=; b=o/lhGp7WfQE0jcMiyJfd2J4rwao8ovTVmtG+tjlI6M5XTrKqGFGlHfdFZSoiqpPzy1 rH3wPuAEL0WhYiMP7OUIBEfPGjKnBvvmJVVN+7oqZ5aLmLkZwFr3jFd0J25iunYQFLSr 785/CAekmLkBEkLcO9zcNtxC40105gCB+1SRhOCbqoduYJR188vEeaThDWc7KV2X2mxk SetIklu2H4eN6ZOOYvcF6iMJgjk9UXsRegzISVQyafPDWfgN/IMLftzRGq5spDNI9lTJ g5LTnnx0z4cgsMCXLiJIrpUw1ZgemjJnSgjzSdXpard408+zMgCT7zhx3i7zNlMF1ZU1 D5oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JcO4wZ3O; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si1798308pfk.350.2018.05.10.14.50.11; Thu, 10 May 2018 14:50:26 -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=@gmail.com header.s=20161025 header.b=JcO4wZ3O; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752674AbeEJVty (ORCPT + 99 others); Thu, 10 May 2018 17:49:54 -0400 Received: from mail-ua0-f174.google.com ([209.85.217.174]:42615 "EHLO mail-ua0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752412AbeEJVtu (ORCPT ); Thu, 10 May 2018 17:49:50 -0400 Received: by mail-ua0-f174.google.com with SMTP id f3-v6so2312041uan.9; Thu, 10 May 2018 14:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=DSFWYJzFM6jJ60Yq/XuiwoRm/dSecebxbD5Jpc9pygw=; b=JcO4wZ3OVrMzhatoqyBgfhZy3UwWdE9r0XooXOyc4NgifWmjHJDVwKPht392ZIKesu bS2ftJHJzBkBJv0smZBPA/3sGVkfk6nDDrLouOBJep6cbu9x/riXfJkOPcmAlppIqMA3 xZ/4E6v+zv0oa5tXPcso7bAFYZgBKy7y+/PKF7emjLhTwwDSRZXi0yEq5jBHVtdKQoK/ 6c4bUy12bhJ3Xf0YA5EfPeD1E0eEaPn2h3UMOFSKOqtQpW/6nbnmXYesq3NM7KzEsD84 u5RbNO4pPRErmuG+7huSjLA44w61l3iYIUZWAzl7JHdFqvJTR47wh/jPTNs7Rk13msox 3HLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=DSFWYJzFM6jJ60Yq/XuiwoRm/dSecebxbD5Jpc9pygw=; b=Ml4a61R4dV0kYeHLgAORGrGUu/AOC+BkMgC8wBndTEpuaQ34ARVH9yJ6Mhe5BztNCh cn/wMg3P9BHq2KojF7ME7gBKiFiuKTS+PGf2FHEdSJWd4a6vupy9vjXIkD8z3Ku+xYoT Z0F4BU86d6oOUBfdmdWlmUJ6s+3mQgAWWTekrcsOiN7BHmRpKzHgp0XqB2KuhU1fDSNm bvJVapU0GAp9ffKqxfe07u2b9JN3Yum5Jbs+NI5/OjKzQnXMi35x57xtGQbbexJNqW+s a/l8PXHTDkYxcGP6vVrCHz8kG9ZyajsgdPq6YUPQ2HvOEScNQWI30b86ys3jggnDstFR gF/Q== X-Gm-Message-State: ALKqPwdKPxSD49dpyRNNNfXJ+/EUm/rfYIoTFVGB9v+SDeZXcIQ64Rh/ v1xivkyrbrEQTGr3rapCrrLsJxkqn27lDM1H9PQ= X-Received: by 2002:a9f:26a2:: with SMTP id 31-v6mr2389773uay.46.1525988988822; Thu, 10 May 2018 14:49:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.151.90 with HTTP; Thu, 10 May 2018 14:49:08 -0700 (PDT) In-Reply-To: References: <94eb2c0ce3aa27cfa40561ec2dc3@google.com> <1515048794.131759.4.camel@gmail.com> <20180509073754.GG711@sol.localdomain> From: Willem de Bruijn Date: Thu, 10 May 2018 17:49:08 -0400 Message-ID: Subject: Re: KASAN: use-after-free Read in __dev_queue_xmit To: Eric Dumazet Cc: Eric Biggers , syzbot , alexander.deucher@amd.com, Andrey Konovalov , Anoob Soman , Chris Wilson , David Miller , "Reshetova, Elena" , Greg Kroah-Hartman , Kees Cook , LKML , Mike Maloney , mchehab@kernel.org, netdev , "Rosen, Rami" , Sowmini Varadhan , syzkaller-bugs@googlegroups.com, Willem de Bruijn Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 9, 2018 at 5:05 PM, Willem de Bruijn wrote: > On Wed, May 9, 2018 at 3:36 PM, Eric Dumazet wrote: >> >> >> On 05/09/2018 12:21 PM, Willem de Bruijn wrote: >> >>> Indeed. The skb shared info struct is zeroed by dev_validate_header >>> as a result of dev->hard_header_len exceeding skb->end - skb->data. >>> >>> Not exactly sure yet how this can happen. The hard header length space >>> is accounted for during allocation as reserved memory. But, >>> packet_alloc_skb does call skb_reserve(), moving skb->data >>> effectively beyond this reserved region. >>> >>> It may be incorrect to pass skb->data to dev_validate_header, as that >>> does not point to the start of the ll_header anymore. Still figuring out what >>> the right fix is.. The following resolves the issue. packet_alloc_skb already calls skb_reserve(skb, reserve), so now the network header should start at 0, not at reserve. If SOCK_DGRAM, dev_hard_header() calls skb_push for the link layer and returns this offset. If SOCK_RAW, we should do the same and use the reserved space to write the link layer. Now behavior is the same as in tpacket_snd. @@ -2898,19 +2911,26 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) tlen = dev->needed_tailroom; linear = __virtio16_to_cpu(vio_le(), vnet_hdr.hdr_len); linear = max(linear, min_t(int, len, dev->hard_header_len)); skb = packet_alloc_skb(sk, hlen + tlen, hlen, len, linear, msg->msg_flags & MSG_DONTWAIT, &err); if (skb == NULL) goto out_unlock; - skb_set_network_header(skb, reserve); + skb_reset_network_header(skb); err = -EINVAL; if (sock->type == SOCK_DGRAM) { offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len); if (unlikely(offset < 0)) goto out_free; + } else { + skb_push(skb, dev->hard_header_len); } /* Returns -EFAULT on error */ err = skb_copy_datagram_from_iter(skb, offset, &msg->msg_iter, len);