Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp18389imm; Thu, 30 Aug 2018 07:21:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZvsBTnaPhlCpZf5IbY/96TGxlO1KxcRzt17Gi2iXKFW44jsBxS6TRXyg0TxNbvj+MJPJeS X-Received: by 2002:a63:6745:: with SMTP id b66-v6mr10326118pgc.248.1535638886769; Thu, 30 Aug 2018 07:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535638886; cv=none; d=google.com; s=arc-20160816; b=VsL2v9baGF9dLxdiZUu6y0gWQXJ7M4jwdB/ZhBd8VsZ+euQQV5p8JFVQe2EN0U6okb uY2B1cOaXFz+wPh5Jwfa1zo/AULOFuBWBweNzvaw7DgsMZXdukY4slJ2zomTSWanSlnT S8nrWLQDeCsxKxtQ4vzEE7uB383WewSAEXGnEDkQUdF0QxvjA8D8/s0AcIaVKDpObscq s634fiPkJQsTCsLZ7ieG+LwEPWpL/nu+rZ+m7ub90J133HfnviKq3t6xZ/8ytvZP6F4P pIwRxMucTMBmwIoAqruYjGWfJVu+BHTRueJ91hnHkZLGlxTIQVAujNfUbFBtGWhHQEXc mU9A== 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=V/HI96+g1hthoJ+H54iIa0R/hHe4c1bwCUk2CUrrlFI=; b=oYRCcA/OMWOvUBN4lXxVM6TJuodIzLWITnBf8RixQrWrzjZ28PpnuioEDZPrCXRlLS FtMvIdW8xlfkUa0f070WO1f2eyEuhKAG1MBPuehucilvJJmFdO0OM79u4ksJZdDjKM5q YpOVQXCa3x5Dx3Lsrv6BD4rnfo2nWgF7kVHEhCdeq3yNdLmjirMgOfAql0vLxjJTe+dz ZheGRBfmRvGu6n9/CxMP6XidtVsBsUrioLTD/qUKewCLQFzrcT9dHio4+Bhb8ydDqOH4 Zwwq8Y5wOFuKS+i1pU92kFEBIobNJ6zZkOo7QdNwtjqjoZNRrOMRzE5eMk4AhHGJlwj0 zV6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GHGR+t6D; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12-v6si6850580pgh.264.2018.08.30.07.21.11; Thu, 30 Aug 2018 07:21: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=@google.com header.s=20161025 header.b=GHGR+t6D; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729389AbeH3SV4 (ORCPT + 99 others); Thu, 30 Aug 2018 14:21:56 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40359 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729252AbeH3SVz (ORCPT ); Thu, 30 Aug 2018 14:21:55 -0400 Received: by mail-pl1-f195.google.com with SMTP id s17-v6so3904380plp.7 for ; Thu, 30 Aug 2018 07:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=V/HI96+g1hthoJ+H54iIa0R/hHe4c1bwCUk2CUrrlFI=; b=GHGR+t6D4Y61Qc8ObIumP9aTV3O02G4KAHG9+waTmyIcPoYuKa6A0SATJNJbDrVVP/ r1FXTtesPE4nDuFivhqEgq0Wm3W8WsxXMr74nTqVSj6kcDYLWUv9GU89+oOcpeOuk1s+ NyBATCg1iU8QKRKsN2ZxkZEPs4LO5q8RPg9bo2T53vb5bkNP2mLUj7hJmDyo/jqQ/dO3 2inelrgLb75KIY2XHC1i1HSlRM9msWMGfkWzlDRdGuw2A8wYKfX8LWUicG01SuGt/wTd 3FMYIoEM86o56cPXwRpagsmjzFMWIEXzVdRVWmLf9at1WqWjhUaFxM7Fz1xGZZ5jhH30 VOfQ== 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=V/HI96+g1hthoJ+H54iIa0R/hHe4c1bwCUk2CUrrlFI=; b=P7T80F8hiRdfkC4lygesnq1+clJPlGmRRLQepldrKLBBv8maX7WzLeyZ4PV0iFyxsR LDfYEJwZJA15N3qheQdklZvY96VzLtcDtuGEfKlibCES2Qvzd4hM3SdxWV9zro3ftlwo FwiW2xbBxBtgiX46majc+cTG/Wwmz6T7yASiwSBQTwhblAqUHMNLatpbQNqVFXdkScAR RkAzl8tbTqexUZG6J3cI09pJERCtjRfKUBMSl4bu3We0agYa7axRGXeX0ulwgFZ3oU/V vSIX2IvFxEQHG0R424GlLn9UQU/okuOaufkEWJNZoDcjrDICEEc/XdwD6XtvMx2Oi0f9 l/IQ== X-Gm-Message-State: APzg51BENDLzGyH14ZF1hSxjCLmCiAdAW2Aky9sibqblno+qHy3A0D08 fo8XP+zy7DXJHVf6c/O47dqEBwdnXQcDbwX0X7YDmQ== X-Received: by 2002:a17:902:6f10:: with SMTP id w16-v6mr10320727plk.216.1535638773472; Thu, 30 Aug 2018 07:19:33 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90a:ac14:0:0:0:0 with HTTP; Thu, 30 Aug 2018 07:19:12 -0700 (PDT) In-Reply-To: <279041ab-d449-1bfb-a05d-2d8b0d5c601b@iogearbox.net> References: <000000000000fef39305748083ae@google.com> <20180829134620.GD7369@quack2.suse.cz> <279041ab-d449-1bfb-a05d-2d8b0d5c601b@iogearbox.net> From: Dmitry Vyukov Date: Thu, 30 Aug 2018 07:19:12 -0700 Message-ID: Subject: Re: KASAN: stack-out-of-bounds Read in __schedule To: Daniel Borkmann Cc: Alexander Potapenko , Alexei Starovoitov , netdev , Jan Kara , syzbot+45a34334c61a8ecf661d@syzkaller.appspotmail.com, Jan Kara , linux-ext4@vger.kernel.org, LKML , syzkaller-bugs , "Theodore Ts'o" 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 Thu, Aug 30, 2018 at 2:52 AM, Daniel Borkmann wrote: >>>>> Hello, >>>>> >>>>> syzbot found the following crash on: >>>>> >>>>> HEAD commit: 5b394b2ddf03 Linux 4.19-rc1 >>>>> git tree: upstream >>>>> console output: https://syzkaller.appspot.com/x/log.txt?x=14f4d8e1400000 >>>>> kernel config: https://syzkaller.appspot.com/x/.config?x=49927b422dcf0b29 >>>>> dashboard link: https://syzkaller.appspot.com/bug?extid=45a34334c61a8ecf661d >>>>> compiler: gcc (GCC) 8.0.1 20180413 (experimental) >>>>> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=13127e5a400000 >>>>> >>>>> IMPORTANT: if you fix the bug, please add the following tag to the commit: >>>>> Reported-by: syzbot+45a34334c61a8ecf661d@syzkaller.appspotmail.com >>>>> >>>>> IPv6: ADDRCONF(NETDEV_UP): veth1: link is not ready >>>>> IPv6: ADDRCONF(NETDEV_CHANGE): veth1: link becomes ready >>>>> IPv6: ADDRCONF(NETDEV_CHANGE): veth0: link becomes ready >>>>> 8021q: adding VLAN 0 to HW filter on device team0 >>>>> ================================================================== >>>>> BUG: KASAN: stack-out-of-bounds in schedule_debug kernel/sched/core.c:3285 >>>>> [inline] >>>>> BUG: KASAN: stack-out-of-bounds in __schedule+0x1977/0x1df0 >>>>> kernel/sched/core.c:3395 >>>>> Read of size 8 at addr ffff8801ad090000 by task syz-executor0/4718 >>>> >>>> Weird, can you please help me decipher this? So here KASAN complains about >>>> wrong memory access in the scheduler. >> >> This looks like a result of a previous bad silent memory corruption. >> >> The KASAN report says there is a stack out-of-bounds in scheduler. And >> that if followed by slab corruption report in another task. >> >> fs/jbd2/transaction.c happens to be the first meaningful file in this >> crash, and so that's where it is attributed to. >> >> Rerunning the reproducer several times can maybe give some better >> glues, or maybe not, maybe they all will look equally puzzling. >> >> This part of the repro looks familiar: >> >> r1 = bpf$MAP_CREATE(0x0, &(0x7f0000002e40)={0x12, 0x0, 0x4, 0x6e, 0x0, >> 0x1}, 0x68) >> bpf$MAP_UPDATE_ELEM(0x2, &(0x7f0000000180)={r1, &(0x7f0000000000), >> &(0x7f0000000140)}, 0x20) >> >> We had exactly such consequences of a bug in bpf map very recently, >> but that was claimed to be fixed. Maybe not completely? >> +bpf maintainers > > Looks like syzbot found this in Linus tree with HEAD commit 5b394b2ddf03 ("Linux 4.19-rc1") > one day later net PR got merged via 050cdc6c9501 ("Merge git://git.kernel.org/pub/..."). > > This PR contained a couple of fixes I did on sockmap code during audit such as: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b845c898b2f1ea458d5453f0fa1da6e2dfce3bb4 > > Looking at the reproducer syzkaller found it contains: > > r1 = bpf$MAP_CREATE(0x0, &(0x7f0000002e40)={0x12, 0x0, 0x4, 0x6e, 0x0, 0x1}, 0x68) > ^^^ > > So it found the crash with map type of sock hash and key size of 0x0 (which is invalid), > where subsequent map update triggered the corruption. I just did a 'syz test' and it > wasn't able to trigger the crash anymore. > > #syz fix: bpf, sockmap: fix sock_hash_alloc and reject zero-sized keys Thanks. I am again trying to figure out how/why this causes such bad failure modes. Looking at sock_hash_ctx_update_elem it seems that all of htab_map_hash/lookup_elem_raw/alloc_sock_hash_elem should handle key_size=0 fine hashing/comparing/updating 0 bytes. Do you have any ideas as to what could have gone wrong?