Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1855477rwb; Fri, 19 Aug 2022 10:30:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR67WAtyqHALn8jgw5l38e2F0SNEoGtdbXKSmDT61F0/FISAhVJXDA0BqTcV7xPAQagZJDB2 X-Received: by 2002:a05:6a00:1d0c:b0:536:619:27f2 with SMTP id a12-20020a056a001d0c00b00536061927f2mr4969602pfx.4.1660930216384; Fri, 19 Aug 2022 10:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930216; cv=none; d=google.com; s=arc-20160816; b=J1DYI7ftaEdLXP2iUd47CTK8AdWfuO+oVvPQx5SEyCg+kjbrIK1DLeueUxkJXRnsvW JPaypiuxpdzvuCl6lb0eDV8QYcQ7huAOqgzoTffdF4/EvBxld3YneYVBQVI943YUtXUz 9spB9W/vgu/MtIKasd19NQ9f0xeBXlmWaYUwGIpJcZ70r50UdtFv7AAip1476D+K8HiO DlVuu6NPwYPAjOZcv+sBzKyWiayshOgL34q4dPqmV5Ei6xUS/jEz5nzkDBnY71+ycwL5 5wCzsn02qIrc6pjJB/ahuY+CwG9K30mig+i13ynhkrb8sP8t/yfekKvrG8Ft80Lh4j7F qu/w== 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=f+AH2QsM9TLh85EQcJVcyaV3OT52HS93uQDMRnh86fo=; b=dnPOPk896q3FVlPnhANINcBcpoNibUHeY6euxwoPiiwvAm2IiN/iGBxsd34l307fwu DFjgxsYeLCc6stsB+A7AxPq87B9KMqHpDCF5Tl6jhbSGlzPlck5wKS4eSLl6/8Pps6WR Nhn4vYhb9tsvpdfGSMAWeVc61v8Z7pSvJhXkNV9mbd/w4WVn+0X5iIw+u98V0fA3eZxy tEQmJ0XqTvw3BpeMQMavZbZKhfQzlO68GbYmTw3Wp1SHS/mdT9At6m64pvAuA5xxQCIc fCH94YhKc4u7hY6Lz9nwaQFrOwWfKlW8uuPjk9FIz/tARWY5UK3sW77FYuYLolGOtB51 6y7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=197ds4qF; 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 om9-20020a17090b3a8900b001f28dc085bfsi875934pjb.115.2022.08.19.10.30.05; Fri, 19 Aug 2022 10:30:16 -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=197ds4qF; 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 S1354396AbiHSQx3 (ORCPT + 99 others); Fri, 19 Aug 2022 12:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354605AbiHSQvY (ORCPT ); Fri, 19 Aug 2022 12:51:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5956A12CDE6; Fri, 19 Aug 2022 09:14:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 93495B82816; Fri, 19 Aug 2022 16:08:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E227BC433D6; Fri, 19 Aug 2022 16:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925301; bh=InaW1CtemCWyOs2I41nHjCaQsp2pWF+nl0S9h5SEmyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=197ds4qFqZbY2XrtYkprKl7XhcOXqtKqeuroD9l4RElROo1ne1Z+VzTu6a7HpemWJ D/eO/Z//0EK6q1R++RE5VQMX435u+Ihpz7HS+rt+DCB3shs9zoPMpaOM57mi5PQ3sj GsRWjvllxTyqohuUyw0EXV3LtXHaMSqFIdzHO56k= 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.10 448/545] posix-cpu-timers: Cleanup CPU timers before freeing them during exec Date: Fri, 19 Aug 2022 17:43:38 +0200 Message-Id: <20220819153849.478179293@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 @@ -1286,6 +1286,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