Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7638746rwb; Tue, 15 Nov 2022 15:38:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf46SA3CJ02tMbD3WiGMB2q0YaMiF1xV9xDDBjx39hCa3qppre4HOvJ/lzLqIREketdV59av X-Received: by 2002:a17:906:24cb:b0:78d:4167:cf08 with SMTP id f11-20020a17090624cb00b0078d4167cf08mr16057464ejb.337.1668555520795; Tue, 15 Nov 2022 15:38:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668555520; cv=none; d=google.com; s=arc-20160816; b=hdquAO3dWfOaKYRtFA7q8BhZ0mhXG2B5LiCaVyJTuXzcmkW1MEFMfbmK1v0A2w0pza W2NhWU9q8/WVLuHWdbMI79YS3Xuc/uXBfsIP0WtF7wSrns0I6Qg1QxNRQf3msfI5+WhE hIUPk/fU/HPRbgpusdkwWuCbhQ/C79e9vLzfrOIS1AICJiT/hogLlsJrFpIcjfNdNPPQ 6nzoeiJ21EiormUepga9FpLw7RA1wLQ9VUSp7bLBepgaqi59sRfRoyUB5XQrIL1w6zjF GPmqgEAwicDbGJLZqKkXzA7JN+g9EgFC0SVkr9xeeTOd9rA6XOS7ZHrHiu66n58IbGwp Rghw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=OZL5LNQ/qoo+PMydbsm4DsIY24R1XznjxSjLJYR8vVM=; b=AjivANoZGKI5dAuySrva3njfg63e+s5+0ESgQmD4+eHQTB2NLz23nXF/hoBAhBKjUJ VoegoxdMWlQ5FPRbQ8JDXCBQ4wXW6AEOkiQk9nlUS1dN9WwKTM4LXOyH2FekeLsn7CeD rAJ3XDJnjWz06zmuJy8rKxcrBb27+4MPj4K6pLS8BRiW+9GhYKkluS/PvSmZOpgI+ekO spR9J2xpghZ8OpyZhB0+3Bm0bVTDy/3UICdFl5fOPRITIPzGs0Bgyto4ENOm1OwhN6Lc kG5dm5ZGWe9LEev0+VwAsOspGCyPer3r871+uAF+er1ViFYJdKPDc5+WK9DRmkDvPeud +IZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=fh6HyKDf; dkim=pass header.i=@codewreck.org header.s=2 header.b=GZWtUl4m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf14-20020a1709077f0e00b007add269f2c4si13712177ejc.740.2022.11.15.15.38.19; Tue, 15 Nov 2022 15:38:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=fh6HyKDf; dkim=pass header.i=@codewreck.org header.s=2 header.b=GZWtUl4m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230130AbiKOWQz (ORCPT + 90 others); Tue, 15 Nov 2022 17:16:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbiKOWQy (ORCPT ); Tue, 15 Nov 2022 17:16:54 -0500 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D6EFD95 for ; Tue, 15 Nov 2022 14:16:51 -0800 (PST) Received: by nautica.notk.org (Postfix, from userid 108) id E0D8BC009; Tue, 15 Nov 2022 23:16:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1668550615; bh=OZL5LNQ/qoo+PMydbsm4DsIY24R1XznjxSjLJYR8vVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fh6HyKDf0DVD+mvNnRo1MlBIY64D8IAD+YqyBw55Q9Y8CTc1xc22BhpXIJbFZtMiO v1Tl3w2Id4eLacpHimdWenZzVHR1cVnLcumorPcujCWfyawEM61vqpkqCEfD5pcKMQ fm1/De+3UDCKCFSVKcSPeD4b33KS7AEb5X17orxTYnLKyn7GuKpA7Z85qziIoKhKvx EMbW9GL6Z3HuzvU2W5LmTTJEkL8GVP9hONHgDz4+jeAWqYuCJQWlIewTCWm8M6XBz4 +Ebhmbzy2SRSwCU7i1aHlDxWIyve48PRdxOVlEHW7eAc3TPXfMS3/nDbkJ8YJZ6TX2 FRj7AZbw7yDRA== X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id E7333C009; Tue, 15 Nov 2022 23:16:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1668550614; bh=OZL5LNQ/qoo+PMydbsm4DsIY24R1XznjxSjLJYR8vVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GZWtUl4my76Dw99vycRNoUgSegPrGhpMi9fi7IYYTswgacGz+53Vfkowb3l+qqVuZ 43rxNdMClHGGmUWnkAoAveEQueR2Z7V9TBvDZY9ixRtsxuN79JuQNwbIzaXzZJqliV 7TZwNFHga+FzpOG2JFxghrTLu7qZIGUzSpHz2CLUMnP+4UPTu3woB7Yytke8SgdSQZ dB5hoCm00ebFyleCrpD91Zy3nCnxHT/9i4SUWbtodmDwDkv40Q665KsB0DAVx+iViC gPIYW/9/RsqEKfgHy79y7ctH+6LJbDIag9VQLerjYBDdlEosgoFVrSGZGpYNvGqAOy GKfoZUNaYlw9Q== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id 6a874494; Tue, 15 Nov 2022 22:16:42 +0000 (UTC) Date: Wed, 16 Nov 2022 07:16:27 +0900 From: asmadeus@codewreck.org To: Peng Zhang Cc: ericvh@gmail.com, lucho@ionkov.net, linux_oss@crudebyte.com, dhowells@redhat.com, jlayton@kernel.org, v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+a76f6a6e524cf2080aa3@syzkaller.appspotmail.com Subject: Re: [PATCH v2] fscache: fix OOB Read in __fscache_acquire_volume Message-ID: References: <20221115140447.2971680-1-zhangpeng362@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221115140447.2971680-1-zhangpeng362@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Peng Zhang wrote on Tue, Nov 15, 2022 at 02:04:47PM +0000: > From: ZhangPeng > > Syzbot reported slab-out-of-bounds Read in __fscache_acquire_volume. > > ================================================================== > BUG: KASAN: slab-out-of-bounds in memcmp+0x16f/0x1c0 lib/string.c:757 > Read of size 8 at addr ffff888016f3aa90 by task syz-executor344/3613 > > CPU: 0 PID: 3613 Comm: syz-executor344 Not tainted > 6.0.0-rc2-syzkaller-00327-g8379c0b31fbc #0 > Hardware name: Google Compute Engine/Google Compute Engine, BIOS > Google 07/22/2022 > Call Trace: > > __dump_stack lib/dump_stack.c:88 [inline] > dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106 > print_address_description mm/kasan/report.c:317 [inline] > print_report.cold+0x2ba/0x719 mm/kasan/report.c:433 > kasan_report+0xb1/0x1e0 mm/kasan/report.c:495 > memcmp+0x16f/0x1c0 lib/string.c:757 > memcmp include/linux/fortify-string.h:420 [inline] > fscache_volume_same fs/fscache/volume.c:133 [inline] > fscache_hash_volume fs/fscache/volume.c:171 [inline] > __fscache_acquire_volume+0x76c/0x1080 fs/fscache/volume.c:328 > fscache_acquire_volume include/linux/fscache.h:204 [inline] > v9fs_cache_session_get_cookie+0x143/0x240 fs/9p/cache.c:34 > v9fs_session_init+0x1166/0x1810 fs/9p/v9fs.c:473 > v9fs_mount+0xba/0xc90 fs/9p/vfs_super.c:126 > legacy_get_tree+0x105/0x220 fs/fs_context.c:610 > vfs_get_tree+0x89/0x2f0 fs/super.c:1530 > do_new_mount fs/namespace.c:3040 [inline] > path_mount+0x1326/0x1e20 fs/namespace.c:3370 > do_mount fs/namespace.c:3383 [inline] > __do_sys_mount fs/namespace.c:3591 [inline] > __se_sys_mount fs/namespace.c:3568 [inline] > __x64_sys_mount+0x27f/0x300 fs/namespace.c:3568 > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 > entry_SYSCALL_64_after_hwframe+0x63/0xcd > RIP: 0033:0x7f7d5064b1d9 > Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 14 00 00 90 48 89 f8 48 89 > f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 > f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48 > RSP: 002b:00007ffd1700c028 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 > RAX: ffffffffffffffda RBX: 00007ffd1700c060 RCX: 00007f7d5064b1d9 > RDX: 0000000020000040 RSI: 0000000020000000 RDI: 0000000000000000 > RBP: 0000000000000000 R08: 0000000020000200 R09: 0000000000000000 > R10: 0000000000000000 R11: 0000000000000246 R12: 00000000000f4240 > R13: 0000000000000000 R14: 00007ffd1700c04c R15: 00007ffd1700c050 > ================================================================== > > The type of a->key[0] is char in fscache_volume_same(). If the length of > cache volume key is greater than 127, the value of a->key[0] is less > than 0. In this case, klen becomes much larger than 255 after type > conversion, because the type of klen is size_t. As a result, memcmp() is > read out of bounds. Fix this by adding a check on the length of the key > in fscache_alloc_volume(). > --- > v1 -> v2: > - Make sure the length of cache volume key (klen) fits a signed char > before writing key[0] that'd benefit everyone, thanks to Dominique > Martinet. > > Reported-by: syzbot+a76f6a6e524cf2080aa3@syzkaller.appspotmail.com > Fixes: 62ab63352350 ("fscache: Implement volume registration") > Signed-off-by: ZhangPeng These tags should go above the '---' line, or git am will be confused and drop them. (I assume David or whoever picks this up can manually fix this, letting them comment) That aside: Acked-by: Dominique Martinet > --- > fs/fscache/volume.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/fscache/volume.c b/fs/fscache/volume.c > index a058e0136bfe..cc206d5e4cc7 100644 > --- a/fs/fscache/volume.c > +++ b/fs/fscache/volume.c > @@ -230,6 +230,8 @@ static struct fscache_volume *fscache_alloc_volume(const char *volume_key, > * hashing easier. > */ > klen = strlen(volume_key); > + if (klen > 127) > + goto err_cache; > hlen = round_up(1 + klen + 1, sizeof(__le32)); > key = kzalloc(hlen, GFP_KERNEL); > if (!key) -- Dominique