Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2885207rwb; Mon, 15 Aug 2022 13:17:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR553nXvBrWJfgdzV/t7vI0uuGVW7cuIFVmghkVe+OpJtxNN9C7C9aH733AH2MGNOr+S1L7a X-Received: by 2002:a05:6402:2079:b0:43d:a218:9b8a with SMTP id bd25-20020a056402207900b0043da2189b8amr15633055edb.357.1660594669301; Mon, 15 Aug 2022 13:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594669; cv=none; d=google.com; s=arc-20160816; b=hv/YlWXqMwZIsgnBU3OWJslpWpAOTz4I9at0i6flZJ5yCk3QjV5EiR8i2wuJrHNDcy W4GCoNvjhAa5cI7c0e70LlSDBV2e26NgFi03zs+aBPcDnDts+048abKKnXSP6T9JxkQ+ OYXp9a8QEYrfgK+Iy33RD2MaeKjmU9/31/swl7IJJVfzpcg1KfyKMAJmEkZ1YT6N8mks a6SOmdxAGKezrtVn2cqFA+ayjk4HdwwpZx2szod0fBAbdoh8dVJRnlGZEQdfMtW6gbzE 2tvkCoSHdXm/4SMWMvUv37WAQNh63FsdvVYegWpmE8uPIo7+Et2zSIz1WOgrTJotJs0a Sf3w== 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=jRgfB880cGMmyZyAZLhPYVv4jSnD7X14NM4Z4aUO2uI=; b=q0GoitE1/mLgt52H5z/dEGawSYfOTiPaE4Wo5bLCcvgWOGTYoCftygJeiny+bAMVOe OL3Lqi9rtUUERD0ciWlx0R3ZQLaKhh/kzggE5NywDM2jUi+L0svJU2UTNst88yVhvotR qY7GL/gJ4mU1iuqUe6Qd/CFsjuZjGVcplFtX+oL2GOx4ctE0dz68K/Y44lSDejCDBK2f VLzGRaTYzsRU8IenadNmZ/ApkKvQhnkhmkFGKOFpFz8Ijo80GYWOR0TgyNhS5cLVQm07 JDW0rrAjl1jWVWG1IU+y21KTCiKHhS+3oMF1wxg2H/yfZGG7J6TSsotfZCrVKhNo8dSB QsgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vd+tfKvQ; 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 hp39-20020a1709073e2700b007262c51b07dsi9589274ejc.724.2022.08.15.13.17.22; Mon, 15 Aug 2022 13:17:49 -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=vd+tfKvQ; 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 S1344961AbiHOTsC (ORCPT + 99 others); Mon, 15 Aug 2022 15:48:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345283AbiHOTqU (ORCPT ); Mon, 15 Aug 2022 15:46:20 -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 4D7DF41D3A; Mon, 15 Aug 2022 11:48:58 -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 1F49C61200; Mon, 15 Aug 2022 18:48:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C5E0C433C1; Mon, 15 Aug 2022 18:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589336; bh=DBfHBJGjSyEq4AwZ7wV8PcjiXMuzz6rmByLGNk29E94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vd+tfKvQWXHDIZ2+43bTjsNVpQL23WlE4llD4rWD1bphiwWa9yPDCl8Zu+ZsE1OlN XkVP8ZNxt2rlgAQRvjQ7b4jB3FO4UBfJoamZQ9307xzSAKz1t0avUUYEeGbfxgRWDM i1C8Td3gODdOO90HR+rS/XP2RJQdyzex4StgsLX4= 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.15 686/779] posix-cpu-timers: Cleanup CPU timers before freeing them during exec Date: Mon, 15 Aug 2022 20:05:30 +0200 Message-Id: <20220815180406.680022485@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 @@ -1298,6 +1298,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