Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5287921rwr; Mon, 24 Apr 2023 01:35:25 -0700 (PDT) X-Google-Smtp-Source: AKy350b38jESkR1xmJ5L9PjAxhCxo4HswyFHHpORdAmw6qbxVT04k3VmfLK57ORfj/WtTgJk6YcD X-Received: by 2002:a17:902:d4c4:b0:1a6:6fe3:df91 with SMTP id o4-20020a170902d4c400b001a66fe3df91mr16488028plg.50.1682325324840; Mon, 24 Apr 2023 01:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682325324; cv=none; d=google.com; s=arc-20160816; b=vSIP65dlXCxOHFMUxSFcXwI3wpFoqCGi5e4br7K5ygsTaMVL/2zKe08tnVEkVMlcHb G/a+ccmMB8S3O0vBicdN/SD+G6ifWVRjPDqG8twG3gPiMobvtsp+1bPRGc9vR9xNxijI SvH9LdceB2zyIpWnA0nsHCvQQfb1+MaylNVnq2tK3L7DxxT5rXfVcbpNzfyBX+0hmo01 EXIipAjQdhTpixMybriJU4uzlCKq1wi5ko0CtG9/pofMDf4eSZAasvd/rK6f7aX3QExW HdTf6GaUSGYVTvGD9X5zxQAHj9++7l7AfvBvQeFQtPzEGK+1aYYKJ33QBjCxb369iqak 20CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=j18LTPw/0ZiwBV/EQmierqo28H2NNyEAjpLUZMbxn80=; b=g5AaDTyiNHELMovhZvY+Bh1NrrJAEuBns3SCLvITv+HZszCX65LNcznjLh+jeWWmMU 9MfWKZOTOK9vwthXFBlwnzaZaEPual36+HZs7v5Zn1CYD0TohmW3IdYC2ssu6EriOe2O W3FDnCfK4eSECsIqOnfLNNDLC6EKGybZpB4oYo41CvaAlUZT49efpo7V+8z5TmsMwFyc 40TFxO/OJr0KTeH2bwoW5L27OwqDR8I92qpWhIU7xBaDLnqzaX3DYGNYAIzHhe1WwYKP IvAPHq9ze6shYoMNmTWJNnfR+I6GMxPZjpxMtaLJqGrcuksyjoHUDfV8qcxFWmrRdhNL 761w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=CesUfe+p; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a170902d50300b001a954c47608si7078334plg.266.2023.04.24.01.35.07; Mon, 24 Apr 2023 01:35:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@google.com header.s=20221208 header.b=CesUfe+p; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S231418AbjDXIZ1 (ORCPT + 99 others); Mon, 24 Apr 2023 04:25:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbjDXIZY (ORCPT ); Mon, 24 Apr 2023 04:25:24 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A58D310F3 for ; Mon, 24 Apr 2023 01:25:15 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4efd5e4d302so4117e87.0 for ; Mon, 24 Apr 2023 01:25:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682324713; x=1684916713; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=j18LTPw/0ZiwBV/EQmierqo28H2NNyEAjpLUZMbxn80=; b=CesUfe+p8d0dkEmrufChgURYmQzPVsRKB6Z1zq/0m7jQFerLN1vm3sKO5u2K/rl8sJ 753Xb1kwNpqsBLPPmYoA5D+gusVtmDUbYgFOfDLoue7QdZQWNHon9ozJTA5RjVwFMkRL AnIoCuhdETOi2d3M+DoGmCRI0qslU+tTb1mfNS7drK8UaW9VeLrCnkq4Fqi2j5alos/A IZikzBkRNKNvM0btTwz4vgI7z6JQ0rR5oqbZStxatygVFvg2zG7l8lGwK2GYsyt17272 RWCij0rqF2sPbmgGniN/jpu8ahpeTEhNwAAwPrUPETEnOkOGoHjSz5eh3iai5awtX9jQ I5Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682324713; x=1684916713; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j18LTPw/0ZiwBV/EQmierqo28H2NNyEAjpLUZMbxn80=; b=lGijNKKW0h6t8fwEuuCi0Zh+Ao6d88meUxE2NcMawJJ/z/FAH0SRDhD/lBizzfhE5p DCDd18dJaQAUFrnLjXjVuKMxk3P46Jmd16bOm7KZevARJSJ7CcXhEllBPJLkcc6L95tM /NFTUgBkKr6TbTiHdr6TvdG9EBeKHwXuf/w+gatZU59QdXS1NJMDcWTdsDd79OqXGGh1 +MkrsmkI4D/XxrMSTrBIPWpsrMyTRdK3mV7tIKtowRyemirPpuzF/RHbldfvOin/YYSp GSmdpAuRKETf8N5+EFZOpdR3lFiPDkfgoy/nxc8tvFOmdC1JuVTPhkV/7heaLbQnt9oS lMVg== X-Gm-Message-State: AAQBX9d7LQDLznXmmYlm+VIX24X3VniPue+FZhBVutfTOdL40bafxPl1 gDcBBzm3wBoL5RWNm6hlrtxp9AXbyw8G0s3MTYbf9w== X-Received: by 2002:a05:6512:239b:b0:4ea:e5e2:c893 with SMTP id c27-20020a056512239b00b004eae5e2c893mr151496lfv.1.1682324713337; Mon, 24 Apr 2023 01:25:13 -0700 (PDT) MIME-Version: 1.0 References: <000000000000b9915d05f9d98bdd@google.com> <13d484d3-d573-cd82-fff0-a35e27b8451e@oracle.com> <20230424-frucht-beneiden-83a8083a973b@brauner> In-Reply-To: <20230424-frucht-beneiden-83a8083a973b@brauner> From: Dmitry Vyukov Date: Mon, 24 Apr 2023 10:25:00 +0200 Message-ID: Subject: Re: [syzbot] [ext4?] [mm?] KCSAN: data-race in strscpy / strscpy (3) To: Christian Brauner Cc: Mike Christie , Matthew Wilcox , syzbot , adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, nathan@kernel.org, ndesaulniers@google.com, syzkaller-bugs@googlegroups.com, trix@redhat.com, tytso@mit.edu, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , martin.lau@linux.dev, bpf , KP Singh , Ingo Molnar , Peter Zijlstra Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon, 24 Apr 2023 at 09:59, Christian Brauner wrote: > > On Fri, Apr 21, 2023 at 12:40:45PM -0500, Mike Christie wrote: > > cc'ing Christian, because I might have fixed this with a patch in > > his tree. > > > > On 4/21/23 9:58 AM, Matthew Wilcox wrote: > > > I'm not sure how it is that bpf is able to see the task before comm is > > > initialised; that seems to be the real race here, that comm is not set > > > before the kthread is a schedulable entity? Adding the scheduler people. > > > > > >>> ================================================================== > > >>> BUG: KCSAN: data-race in strscpy / strscpy > > >>> > > >>> write to 0xffff88812ed8b730 of 8 bytes by task 16157 on cpu 1: > > >>> strscpy+0xa9/0x170 lib/string.c:165 > > >>> strscpy_pad+0x27/0x80 lib/string_helpers.c:835 > > >>> __set_task_comm+0x46/0x140 fs/exec.c:1232 > > >>> set_task_comm include/linux/sched.h:1984 [inline] > > >>> __kthread_create_on_node+0x2b2/0x320 kernel/kthread.c:474 > > >>> kthread_create_on_node+0x8a/0xb0 kernel/kthread.c:512 > > >>> ext4_run_lazyinit_thread fs/ext4/super.c:3848 [inline] > > >>> ext4_register_li_request+0x407/0x650 fs/ext4/super.c:3983 > > >>> __ext4_fill_super fs/ext4/super.c:5480 [inline] > > >>> ext4_fill_super+0x3f4a/0x43f0 fs/ext4/super.c:5637 > > >>> get_tree_bdev+0x2b1/0x3a0 fs/super.c:1303 > > >>> ext4_get_tree+0x1c/0x20 fs/ext4/super.c:5668 > > >>> vfs_get_tree+0x51/0x190 fs/super.c:1510 > > >>> do_new_mount+0x200/0x650 fs/namespace.c:3042 > > >>> path_mount+0x498/0xb40 fs/namespace.c:3372 > > >>> do_mount fs/namespace.c:3385 [inline] > > >>> __do_sys_mount fs/namespace.c:3594 [inline] > > >>> __se_sys_mount+0x27f/0x2d0 fs/namespace.c:3571 > > >>> __x64_sys_mount+0x67/0x80 fs/namespace.c:3571 > > >>> do_syscall_x64 arch/x86/entry/common.c:50 [inline] > > >>> do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80 > > >>> entry_SYSCALL_64_after_hwframe+0x63/0xcd > > >>> > > >>> read to 0xffff88812ed8b733 of 1 bytes by task 16161 on cpu 0: > > >>> strscpy+0xde/0x170 lib/string.c:174 > > >>> ____bpf_get_current_comm kernel/bpf/helpers.c:260 [inline] > > >>> bpf_get_current_comm+0x45/0x70 kernel/bpf/helpers.c:252 > > >>> ___bpf_prog_run+0x281/0x3050 kernel/bpf/core.c:1822 > > >>> __bpf_prog_run32+0x74/0xa0 kernel/bpf/core.c:2043 > > >>> bpf_dispatcher_nop_func include/linux/bpf.h:1124 [inline] > > >>> __bpf_prog_run include/linux/filter.h:601 [inline] > > >>> bpf_prog_run include/linux/filter.h:608 [inline] > > >>> __bpf_trace_run kernel/trace/bpf_trace.c:2263 [inline] > > >>> bpf_trace_run4+0x9f/0x140 kernel/trace/bpf_trace.c:2304 > > >>> __traceiter_sched_switch+0x3a/0x50 include/trace/events/sched.h:222 > > >>> trace_sched_switch include/trace/events/sched.h:222 [inline] > > >>> __schedule+0x7e7/0x8e0 kernel/sched/core.c:6622 > > >>> schedule+0x51/0x80 kernel/sched/core.c:6701 > > >>> schedule_preempt_disabled+0x10/0x20 kernel/sched/core.c:6760 > > >>> kthread+0x11c/0x1e0 kernel/kthread.c:369 > > >>> ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 > > >>> > > > > > > I didn't see the beginning of this thread and I think the part of the > > sysbot report that lists the patches/trees being used got cut off so > > I'm not 100% sure what's in the kernel. > > > > In Linus's current tree we do set_task_comm in __kthread_create_on_node > > after waiting on the kthread_create_info completion which is completed by > > threadd(). At this time, kthread() has already done the complete() on the > > kthread_create_info completion and started to run the threadfn function and > > that could be running. So we can hit the race that way. > > > > > > In linux next, from > > https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/log/?h=kernel.user_worker > > we have: > > > > commit cf587db2ee0261c74d04f61f39783db88a0b65e4 > > Author: Mike Christie > > Date: Fri Mar 10 16:03:23 2023 -0600 > > > > kernel: Allow a kernel thread's name to be set in copy_process > > > > and so now copy_process() sets the name before the taskfn is started, so we > > shouldn't hit any races like above. > > Yeah, that looks like it should fix it. > > Afaict, this has no reproducer so there's no point in letting syzbot > test on this. I've sent the pull request for the kernel user worker > series on Friday. So I guess we'll see whether it's reproducible on > v6.4-rc1. To see if it still happens to tell syzbot about the fix, then it will remind if it still happens with the fix or not. Otherwise everybody will forget about this tomorrow ;) #syz fix: kernel: Allow a kernel thread's name to be set in copy_process Btw, a similar race will still be possible b/c it's possible to change the name at any point by writing to /proc/self/task/[tid]/comm. But I am not sure how provably dangerous it will be and there is a different attitude towards fixing races proactively for different kernel subsystems, so we will probably not report it.