Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3083762rwb; Mon, 15 Aug 2022 17:43:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR74/U+w2dzrV8QJrUNt9Hbr4is+lN9WzhpTXjymKOkFlXVIhhxzAkuAJPWq0Hlwk0dbSAmD X-Received: by 2002:a17:907:9707:b0:731:5ddc:30f3 with SMTP id jg7-20020a170907970700b007315ddc30f3mr11792224ejc.338.1660610632590; Mon, 15 Aug 2022 17:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610632; cv=none; d=google.com; s=arc-20160816; b=s+LDIyzyFirtMOvq9czw5UYEbBs4qONUi0HA+F5V12cp/HbIE/6e2dYOPfNHbAdHZx oVSilmko1V3PFmUVYO5FjnZkbsglMuS7IsFnG3hYGaw9zHdpaRAIQxzw3dAWZvJ8rXdh I2P9Kchma6FofhbeU+GrNeOAMQe5DwbRWmzE+5IJW3N7//DIiN8jGS205Ks8DRoZIv4g Jy3+1VaFEDVzPm+M6yDfaROPsHOw907N/0T44TDWfZwojCEAEtr0IGNbv9B/BD+4ArPK kSamNr4sNWmTa6pqI9rVDIQ8iIveufiGrk1E6winFLmiYwkz8GL6SQp3AcQKHDm22bY8 NSnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4X41fYYbzpM1OLckNFUiGS23ugqw9MU14CR+5EhWyGg=; b=U9RlKsAuL1SS0NDf6nluec7OykQrCWNSDnGVqZxZXD/1/CeovfcvDTcbQM1Rm3DGc3 L24Ro1t1rQbGzc/kMXBMTf9xanUM+UYrhU6sHox2/RTCXY47oITU6WkPljgLQdKUu7Zr TuPQuz7rmvVgfYRCLpuf6DGHxe3kHUYxYGULJiE01jcwrlkSn1taUDpfDtuPRshN0vGU IuqCK1ovU2JU545NHIJkt3lmg9CC3Z28ZtVoUSbeSqoWuoD33sc9i4lbx7nf3olpC3Dk dWsG2gQO+sN3cSFTAHl0Gw/VCsbZpMSanzx/K+udCeI/Ct0Xcba4d0w50OTiuQ3pQMNG wfzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DvLgj34x; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb16-20020a170907161000b00726ed19161bsi10750994ejc.921.2022.08.15.17.43.27; Mon, 15 Aug 2022 17:43:52 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=DvLgj34x; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345864AbiHOXM6 (ORCPT + 99 others); Mon, 15 Aug 2022 19:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232933AbiHOXLg (ORCPT ); Mon, 15 Aug 2022 19:11:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8542238B3; Mon, 15 Aug 2022 13:00:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 99AEB612B8; Mon, 15 Aug 2022 20:00:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E38AC433C1; Mon, 15 Aug 2022 20:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593616; bh=HH4qPGidm0OUya6QXERfAKhEFrdc6+v3zuCV1SJ7ZWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DvLgj34xtBjS79KJcY+X2oBoudgW4Gb+klj5T23u+xCtTyF0dAylqFXJbFO/9x9+g Wvwbbt5fDP5j4Gnw2FD6TNwygRfxb6JyalasyPYBMku91+ii0Kge/U8b257Rsac159 srLLmxvR8NtWNIVbvuLWl0R+jVzz9fgMC970ahpY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thadeu Lima de Souza Cascardo , Thomas Gleixner Subject: [PATCH 5.18 0976/1095] posix-cpu-timers: Cleanup CPU timers before freeing them during exec Date: Mon, 15 Aug 2022 20:06:15 +0200 Message-Id: <20220815180509.486593618@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Thadeu Lima de Souza Cascardo commit e362359ace6f87c201531872486ff295df306d13 upstream. Commit 55e8c8eb2c7b ("posix-cpu-timers: Store a reference to a pid not a task") started looking up tasks by PID when deleting a CPU timer. When a non-leader thread calls execve, it will switch PIDs with the leader process. Then, as it calls exit_itimers, posix_cpu_timer_del cannot find the task because the timer still points out to the old PID. That means that armed timers won't be disarmed, that is, they won't be removed from the timerqueue_list. exit_itimers will still release their memory, and when that list is later processed, it leads to a use-after-free. Clean up the timers from the de-threaded task before freeing them. This prevents a reported use-after-free. Fixes: 55e8c8eb2c7b ("posix-cpu-timers: Store a reference to a pid not a task") Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Thomas Gleixner Reviewed-by: Thomas Gleixner Cc: Link: https://lore.kernel.org/r/20220809170751.164716-1-cascardo@canonical.com Signed-off-by: Greg Kroah-Hartman --- fs/exec.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/exec.c +++ b/fs/exec.c @@ -1297,6 +1297,9 @@ int begin_new_exec(struct linux_binprm * bprm->mm = NULL; #ifdef CONFIG_POSIX_TIMERS + spin_lock_irq(&me->sighand->siglock); + posix_cpu_timers_exit(me); + spin_unlock_irq(&me->sighand->siglock); exit_itimers(me); flush_itimer_signals(); #endif