Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp677187rdb; Tue, 19 Sep 2023 07:12:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFm8rq3zLEly3djmYFszdFlGvFuG9kJ7pKYGCWcxMQCztyZt3CYj8leauF+BOabpIPDfjuU X-Received: by 2002:a05:6a21:819b:b0:11d:4c79:90ee with SMTP id pd27-20020a056a21819b00b0011d4c7990eemr12495514pzb.25.1695132737436; Tue, 19 Sep 2023 07:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695132737; cv=none; d=google.com; s=arc-20160816; b=TWe4VzFadvltlC/VdkFE2s8UOTkyOevmQxdsqbCw6vLN1hlP5iS87V2BVZ9OBFx+RJ VsJ2z7tyhJaHCZvzxhgUQ1tUoYxGMGqI6tTlRkcvBBW9tDxuf54t2fJUKy+iY6DlwIgc o9tMJ/Ft2JuwYn87M++O7WbDnhFR5NJxhcp7zwAp/w/fn67qYf8XHH3SW9+Wv9BFxwHj 6xby32j2UrthnkGypJx5B27+wKGnQiDxz/Jx9aYcPfnM7vx8Ij0qrUqpIxcOrZH7NK/r p3uPGjuP00+0nMLaBUOVbJZ2AjB/shTs95B/SkM0mq8emXUBvUvLsxGmpCuxDpL0BVpo BjiQ== 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; bh=QXs2a8eD9JuWpImPXplS7bjZ/mwT38MbbloUG5yxoO8=; fh=0T/Cz/6kfzyq4MPg6wrhuDkAsXxv4Wnv+2jNEKRU/s0=; b=Gf8oH9B7Iry4w0KsyV9HWM5YMYoIl04tlRMiH+tniZtNV1JH4QCMMifHt/4/X5bo18 wTiWQq8edWtQTYvSVxdDDNADi/GpdSE3EX7/sCuwswXYAUw7uUbsll24IwLQC4jO1YmN GoWqGJfinmfF+zoFCT4qt1chNMxk5L4mHyBtQK1O8Dkfo5IQodN8BLXO61SJtis4BwRO DG1B92+RiZAILIDdoxTK1jGOm2lAEgHcrafCeNRP+8INZGuf9yxVnTysWSUaL0CO5Mth Vl0OZ6ts2GOP67M7/xS8knIHfDOkTx2eIOZa8uvgeJaB2WdZPqf9ZiPBRoXkJl7DQg/6 7bXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=h+4gkjE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p9-20020a056a0026c900b00690d55d630dsi24191pfw.274.2023.09.19.07.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 07:12:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=h+4gkjE2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 75DC48092207; Tue, 19 Sep 2023 06:10:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231882AbjISNKu (ORCPT + 99 others); Tue, 19 Sep 2023 09:10:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231939AbjISNKt (ORCPT ); Tue, 19 Sep 2023 09:10:49 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA7B8F4 for ; Tue, 19 Sep 2023 06:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=QXs2a8eD9JuWpImPXplS7bjZ/mwT38MbbloUG5yxoO8=; b=h+4gkjE20ihoPRya6zT4bK2QOd 0xJnoF3tC+jloVqHO9zirAV51Xfz8+zrpxblMIC31odnAtrzQfDh/OdkC0S4UwLyVMbMNOCvIjODK fLaSJaSLtknwmDMs+R5OT4iMkKUbmZw8AE8IXa9v5UtZwhz4S6dGaUCSRbgHvojXdPdKwbYUt7a8L lD4owL+V3UjBrDLo+seEZKvBLHAlm0Dp9pj65XAwx6jn8pzzAj+Bkp3yWKItUVximTukyvXwI0Czg u6jxmKJ8d87cnXUfIZg2ngwXHLTwhpEshnsdWEJQOUaMXio2ZZtQ0t9/TnU2GieDz8CEfoXvZcnHV uOOgHesg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qiaUv-00DcZW-0H; Tue, 19 Sep 2023 13:10:38 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 31375300585; Tue, 19 Sep 2023 15:10:38 +0200 (CEST) Date: Tue, 19 Sep 2023 15:10:38 +0200 From: Peter Zijlstra To: Linus Torvalds Cc: Bartosz Golaszewski , Alexey Dobriyan , linux-kernel@vger.kernel.org, Linus Walleij , akpm@linux-foundation.org Subject: Re: Buggy __free(kfree) usage pattern already in tree Message-ID: <20230919131038.GC39346@noisy.programming.kicks-ass.net> References: <20230915210851.GA23174@noisy.programming.kicks-ass.net> <20230915213231.GB23174@noisy.programming.kicks-ass.net> <20230915221332.GC23174@noisy.programming.kicks-ass.net> <20230919125752.GA39346@noisy.programming.kicks-ass.net> <20230919125954.GB39346@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230919125954.GB39346@noisy.programming.kicks-ass.net> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham 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-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 06:10:50 -0700 (PDT) On Tue, Sep 19, 2023 at 02:59:54PM +0200, Peter Zijlstra wrote: > + scoped_guard (mutex_intr, &task->signal->cred_guard_mutex) { > > + scoped_guard (task_lock, task) { > + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH_REALCREDS); > + if (retval) > + return retval; > + } > > + scoped_guard (write_lock, &tasklist_lock) { > + if (unlikely(task->exit_state)) > + return -EPERM; > + if (task->ptrace) > + return -EPERM; > > + task->ptrace = flags; > > + ptrace_link(task, current); > + > + /* SEIZE doesn't trap tracee on attach */ > + if (!seize) > + send_sig_info(SIGSTOP, SEND_SIG_PRIV, task); > + > + ptrace_set_stopped(task); > + > + } > + > + goto success; > } > + return -ERESTARTNOINTR; > > +success: > + /* > + * We do not bother to change retval or clear JOBCTL_TRAPPING > + * if wait_on_bit() was interrupted by SIGKILL. The tracer will > + * not return to user-mode, it will exit and clear this bit in > + * __ptrace_unlink() if it wasn't already cleared by the tracee; > + * and until then nobody can ptrace this task. > + */ > + wait_on_bit(&task->jobctl, JOBCTL_TRAPPING_BIT, TASK_KILLABLE); > + proc_ptrace_connector(task, PTRACE_ATTACH); > + > + return 0; This isn't exactly nice.. I tried something like: scoped_cond_guard (mutex_intr, return -EINTR, &task->signal->cred_guard_mutex) { ... } Which I can make work, but then I also tried to capture my other case: scoped_cond_guard (rwsem_down_intr, if (task) return -EINTR, task ? &task->signal->exec_guard_mutex : NULL) { ... } But I can't get that to work because of that extra if, the not case doesn't fall through and do the body. Anyway, I'll poke more..