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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF78AC28B30 for ; Sun, 23 Mar 2025 18:15:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E57E280004; Sun, 23 Mar 2025 14:15:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36ED3280003; Sun, 23 Mar 2025 14:15:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2367C280004; Sun, 23 Mar 2025 14:15:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 012DE280003 for ; Sun, 23 Mar 2025 14:15:10 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 77FF2160489 for ; Sun, 23 Mar 2025 18:15:11 +0000 (UTC) X-FDA: 83253617622.27.3C190DC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 65BA4160013 for ; Sun, 23 Mar 2025 18:15:09 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LLzhWvwV; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742753709; a=rsa-sha256; cv=none; b=BXkwvikEeu2HoRnq+kTE6mz4hYUMsi6WFWtA4txEy9jO0OHtWVYSq7DVcQyJjsdpONqbHy 7zRugcuzwJj99YHFmUSzcMt6lgalB3aHoHQzsXAEHIl0ZT17vFfakpns5EpSv1YE1OixQ7 8pWl+aqQJdOJPOIZ+xUG7Cgs3KAxsGs= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LLzhWvwV; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742753709; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0w5axyZcg98z3a51P4ruVqk9dqgoLr8zEn3jjGLi8f0=; b=0oyeTRyN6l7JRGBrhalr9a5jJlLEQRlzwS6tzHGQsNb7QaoIgMhHEBEMYg/mGWsibrBqS4 6Z5LJ3K8yqzw5ukpor3a8SY7butoyKC20hzRA12Z/SAJkkysXRXz8/IfbwpTblNErscaAx kJHUmCbAkNeAqf8AST3gmJDE1vmq+Qk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742753707; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0w5axyZcg98z3a51P4ruVqk9dqgoLr8zEn3jjGLi8f0=; b=LLzhWvwVTMwqj84M5Hm/1voLqc7kxqkNxDwjT/100LoSdCOJ32Ae1+JOJASocI/PaoUQ3H I/uvdiXjSzC3FDcuF66uyRQ1sACOjJexeoncYgyiwnFbzGPqQBXrCg4lLdMDTJ5W2EDZq2 9UMrK0y2ETiqAvf+zONYavAc87GsdOo= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-imhGZ1CaPqSBS4hhHCfZrQ-1; Sun, 23 Mar 2025 14:15:01 -0400 X-MC-Unique: imhGZ1CaPqSBS4hhHCfZrQ-1 X-Mimecast-MFC-AGG-ID: imhGZ1CaPqSBS4hhHCfZrQ_1742753699 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BD5F0196D2CD; Sun, 23 Mar 2025 18:14:58 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.42]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 8A03230001A1; Sun, 23 Mar 2025 18:14:55 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 23 Mar 2025 19:14:25 +0100 (CET) Date: Sun, 23 Mar 2025 19:14:21 +0100 From: Oleg Nesterov To: Al Viro Cc: Christian Brauner , Kees Cook , jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, syzbot Subject: Re: [syzbot] [fs?] [mm?] KCSAN: data-race in bprm_execve / copy_fs (4) Message-ID: <20250323181419.GA14883@redhat.com> References: <67dc67f0.050a0220.25ae54.001f.GAE@google.com> <202503201225.92C5F5FB1@keescook> <20250321-abdecken-infomaterial-2f373f8e3b3c@brauner> <20250322010008.GG2023217@ZenIV> <20250322155538.GA16736@redhat.com> <20250322185007.GI2023217@ZenIV> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250322185007.GI2023217@ZenIV> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Queue-Id: 65BA4160013 X-Stat-Signature: dcnwipk5iyd4eostd3dcg5h7x4atxprd X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1742753709-405243 X-HE-Meta: U2FsdGVkX19hm6Jx/t4dMH0wEBizyjj9BrGbqUhumWlLJn1QRnKWuRsUIQYYpmexgQC75mfvlveGvqaVlu4byhd38r8LwUqCpqg3uqnJn9u7GuEaY+90sEoXJtbiCIdVN56Kcfpk4uVqzp/VlIfbDzW3TkavLMoHuYtVw+3Yu0Li6qBqnciCqOQhh7NBmIo9enG+WSH5JX8fMpjCikJHCychoZu7GS/dVLXwmTZaOibVX+aA2wN7ishcSLqTwwgJ+7+Nhvb5118+pXQsrWJKeEFyH/lMGCYZEo+mm79t3o4cfKkPfeo505GWgEPy64MUStS/Yk6hPhNnWgjq2DjcQJjvnPiIbRCHV9GfPRM2jrroDipX5ZS7MmaIeh6tR3cis+XkzAs8tSeUubHerVlz9LzQhKuN2qTYebY9OLlYy0sgra7C4uTI/2Fm1qeKV4FMdUkx6TBccsxgnG5UHSxi9yWpjl9+w2zdhdUcCGv5njRfG1CKZy+J5bpTkctjk6ZrTBVqKpbN5AP6F7hFzBtlvcV0cZ5TxxloQ2JMzOyF9JaOq7+lAwAKBAkrPfA0Xc/LPx6FHCFL+ktZaKN3eFCY4oFRdsU+MSVaEmnjljJlHz1WNT3j1gjsEJ41zVum4JtVcd5gcnoURd0sAJiNZL+ZLCFq0SyzXKzp5boRi0wYKD0iX44bqLercrYQsYYsVm+QB8dr4/UTcAjpo9/USmIzGX6SdtW4nGVULfeuALHFnvoeu38xBJaRxPfcsx4iAO81Guvdb/oSNjvwdqJfRyo3Tcw32bsgf90DwUroAb+16A/Tqcxmw3V3rODbzpSA9bQVsITBadRsFwRJT+2Nf5G+t6ZhAAVaI1gh4OsWNOFNzFiHc5FSEkP42bUImhkgK7nPz1cxFgahaPWphUyI89y0FFQHchPWaod3Bjz0qcAFHLb6eRuWHT55UBFYcrTpX0ldTWGAfaS16onwyhsLHhy ARLtZplU 5yhmuaD+nfZRTg8lhueaaGZgDiuNr6P9JHHvNXSNRRox6oJsaRwzOT9h+HnlzTNeV2/Z9ttW8i4Brj+xLNYLkhoTG6etTXBoGkSZek57f+/gU/0JcbcC8H1JruHMvbV+jL1f+53yfVJ/1/hO2gVPx950/H4tSdqvoazWtmTfVH86xdsWx1JIix7XwR5rIE+tv1D5ZkPJxe+LtHheA4T1x83Fk8fRf69tGyK1QemZIJWi24BP9gh3vXnbJIQw3wdWVM2a9tuRfF+ZzrT/1a6RrWI2wAavDkothAZZSxInifA2W6uNmgG2bAnGcaq10THLezGkXWUpzm9krdDswyccEsayO/dd9dAWxdBq1sqQugCZ/15Q785dYEN7X0BrdZihDepPVHmPavtmEybqRzBqhRBf5N4r2Rni7ZaEALWr/T3SckgdxdcWyI0mZhVAWB6f92abO6ATgllmvx/2az+Yvx2tRd9/VyR9leEEUDMYihgrWl8NdfKYthh6fBsCesn9q1KZb X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 03/22, Al Viro wrote: > > On Sat, Mar 22, 2025 at 04:55:39PM +0100, Oleg Nesterov wrote: > > > And this means that we just need to ensure that ->in_exec is cleared > > before this mutex is dropped, no? Something like below? > > Probably should work, but I wonder if it would be cleaner to have > ->in_exec replaced with pointer to task_struct responsible. Not > "somebody with that fs_struct for ->fs is trying to do execve(), > has verified that nothing outside of their threads is using this > and had been holding ->signal->cred_guard_mutex ever since then", > but "this is the thread that..." perhaps... or something else to make this "not immediately obvious" fs->in_exec more clear. But I guess we need something simple for -stable, so will you agree with this fix for now? Apart from changelog/comments. retval = de_thread(me); + current->fs->in_exec = 0; if (retval) current->fs->in_exec = 0; is correct but looks confusing. See "V2" below, it clears fs->in_exec after the "if (retval)" check. syzbot says: Unfortunately, I don't have any reproducer for this issue yet. so I guess "#syz test: " is pointless right now... Oleg. --- diff --git a/fs/exec.c b/fs/exec.c index 506cd411f4ac..02e8824fc9cd 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1236,6 +1236,7 @@ int begin_new_exec(struct linux_binprm * bprm) if (retval) goto out; + current->fs->in_exec = 0; /* * Cancel any io_uring activity across execve */ @@ -1497,6 +1498,8 @@ static void free_bprm(struct linux_binprm *bprm) } free_arg_pages(bprm); if (bprm->cred) { + // for the case exec fails before de_thread() + current->fs->in_exec = 0; mutex_unlock(¤t->signal->cred_guard_mutex); abort_creds(bprm->cred); } @@ -1862,7 +1865,6 @@ static int bprm_execve(struct linux_binprm *bprm) sched_mm_cid_after_execve(current); /* execve succeeded */ - current->fs->in_exec = 0; current->in_execve = 0; rseq_execve(current); user_events_execve(current); @@ -1881,7 +1883,6 @@ static int bprm_execve(struct linux_binprm *bprm) force_fatal_sig(SIGSEGV); sched_mm_cid_after_execve(current); - current->fs->in_exec = 0; current->in_execve = 0; return retval;