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 X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF987C433EF for ; Sat, 4 Sep 2021 06:09:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D56E60FDC for ; Sat, 4 Sep 2021 06:09:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233426AbhIDGKU (ORCPT ); Sat, 4 Sep 2021 02:10:20 -0400 Received: from home.keithp.com ([63.227.221.253]:36028 "EHLO elaine.keithp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232224AbhIDGKP (ORCPT ); Sat, 4 Sep 2021 02:10:15 -0400 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 132B93F30826; Fri, 3 Sep 2021 23:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1630735729; bh=TiBQjRhgDSbNjx047iON2OqbTV5dVpsECJ5EVpXAQx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EdC4AZMs592lphtlw4x0KzeVVCLMQIJ+eBX9QPBdPbCCQii4OWQ7EzMMq4vfrE+TR XUzhJ06rr2GW1hTq01825KsIln9+kJnDijL0OGHXXZLdYVa7WXO772uHsmeC5exkHe YWVMVHKkvmKGJwaQ8Mhz9UDfzXx0jjMMl8vA7wmO52w7LdsU+y81fRuQfGsnI1pAd2 1X6SU6Q6gL7C0lIX2RhwR+hJeVqI9UgR698x+fgJoX5Hg63xZrtdTQyKGZiiLZGNZm wuVO8Rb8LvkFKQyqhLIgW2ZsUihCclq3ti3oXaOj/g01HzhhWKHQeDjjjjDQHOxa+7 eOYWCc+n2A5SA== X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id d4vRelaLlD2U; Fri, 3 Sep 2021 23:08:48 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id 670813F30823; Fri, 3 Sep 2021 23:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1630735728; bh=TiBQjRhgDSbNjx047iON2OqbTV5dVpsECJ5EVpXAQx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dp8zjbvLOiyFLpBahF7z3Sv1YeCcWsU52OuLP1wDBt1ymSAxt6+PvAjRHhXyvV7Xg 41YStC+dh+p2UE2qdy9s/BbuXYq9pC1Acov8e4yTOEQvcG0kXrMDQ/BFolB7pGv8gQ /5HHqkxLDSijeigkem2ISW+jBOYnLfWa2J7DaZYD+kJtihraAsnIKxCJ5AJTYFhQMx OtVoQOorkaUWiypXnixuSEG9ZZei9pVO/hw8HW7V92+hjBVhzay8s/SxrlVJ7Fg8BW yc7EQ+VZm0fv9sCjGxVVpn7a7C+bxHz1Ar66Mxo6F3MFZLD7me9ODG5CI1iLGvYa5O heewzlx9InG5A== Received: by keithp.com (Postfix, from userid 1000) id 765121E6013A; Fri, 3 Sep 2021 23:09:10 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Alexander Sverdlin , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Florian Fainelli , Geert Uytterhoeven , Hartley Sweeten , Jens Axboe , Jian Cai , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Miguel Ojeda , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nicolas Pitre , Rob Herring , Russell King , Thomas Gleixner , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu , Keith Packard Subject: [PATCH 0/2] ARM: support THREAD_INFO_IN_TASK (v7 only) (v2) Date: Fri, 3 Sep 2021 23:09:05 -0700 Message-Id: <20210904060908.1310204-1-keithp@keithp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210902155429.3987201-1-keithp@keithp.com> References: <20210902155429.3987201-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Placing thread_info in the kernel stack leaves it vulnerable to stack overflow attacks. This short series addresses that by using the existing THREAD_INFO_IN_TASK infrastructure. This is the second version of this series, in this version the changes are restricted to v7 hardware which offers a way to identify each cpu in the system without reference to the stack it is using. The series is broken into three pieces: 1) Change the secondary_start_kernel API to pass the cpu number to this function. This is required for the following patch because the raw_smp_processor_id() macro will use the per_cpu_offset value which needs to have the cpu number to get the right value. 2) Enable THREAD_INFO_IN_TASK by creating a new per-cpu variable, current_task, just like the x86 architecture. The largest changes are in the assembly code where fetching the current_task value requires a temporary register. Fortunately, each location in the code performing this had a reasonably obvious register to use. 3) Optimize access to the cpu number using another new per-cpu variable. This is not functionally necessary, but avoids de-referencing through two pointers at modest memory cost. Signed-off-by: Keith Packard 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 X-Spam-Level: X-Spam-Status: No, score=-12.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8ED57C433F5 for ; Sat, 4 Sep 2021 06:11:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 576EB60F9C for ; Sat, 4 Sep 2021 06:11:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 576EB60F9C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=keithp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dS5/pLjWW9EzjtZoQpP2sfJtSiFnINKqgX0sRpGNuUk=; b=Zwc6QIOAohU97U 5UMrBOVhgJvI9lYvdAEDmbmmm85bdENhSZJkktrFuD5rFllzfy0BcjPceGkVoeF7SRzKMyGOChEGZ F1AGFQG2jeM3e/iN6TPymfQ1C5tmNzqOMZQT6+LPhsOmu1t3W8TdcTd0mneZHhHafXcoQNGzKTwny DXDMaPuoPfUHKp5mEJscO7fW4uSEigC41b/2KkVdWTBjcFLMRgOeu826wT8ynD8MX7QnHbDg0zJ2Z +g0aBak3pE55u5Y7Bt5CsDbmgoU2i/IHF5aQ0jn9K24Bsf8BeP7acZVRYIZ+hujwfBXG3iEbLfVUl j+kX6NslG0Kl1v6bmG5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mMOri-00Dcvb-7Q; Sat, 04 Sep 2021 06:09:22 +0000 Received: from home.keithp.com ([63.227.221.253] helo=elaine.keithp.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mMOrd-00Dctr-QE for linux-arm-kernel@lists.infradead.org; Sat, 04 Sep 2021 06:09:19 +0000 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 132B93F30826; Fri, 3 Sep 2021 23:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1630735729; bh=TiBQjRhgDSbNjx047iON2OqbTV5dVpsECJ5EVpXAQx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EdC4AZMs592lphtlw4x0KzeVVCLMQIJ+eBX9QPBdPbCCQii4OWQ7EzMMq4vfrE+TR XUzhJ06rr2GW1hTq01825KsIln9+kJnDijL0OGHXXZLdYVa7WXO772uHsmeC5exkHe YWVMVHKkvmKGJwaQ8Mhz9UDfzXx0jjMMl8vA7wmO52w7LdsU+y81fRuQfGsnI1pAd2 1X6SU6Q6gL7C0lIX2RhwR+hJeVqI9UgR698x+fgJoX5Hg63xZrtdTQyKGZiiLZGNZm wuVO8Rb8LvkFKQyqhLIgW2ZsUihCclq3ti3oXaOj/g01HzhhWKHQeDjjjjDQHOxa+7 eOYWCc+n2A5SA== X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id d4vRelaLlD2U; Fri, 3 Sep 2021 23:08:48 -0700 (PDT) Received: from keithp.com (168-103-156-98.tukw.qwest.net [168.103.156.98]) by elaine.keithp.com (Postfix) with ESMTPSA id 670813F30823; Fri, 3 Sep 2021 23:08:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1630735728; bh=TiBQjRhgDSbNjx047iON2OqbTV5dVpsECJ5EVpXAQx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dp8zjbvLOiyFLpBahF7z3Sv1YeCcWsU52OuLP1wDBt1ymSAxt6+PvAjRHhXyvV7Xg 41YStC+dh+p2UE2qdy9s/BbuXYq9pC1Acov8e4yTOEQvcG0kXrMDQ/BFolB7pGv8gQ /5HHqkxLDSijeigkem2ISW+jBOYnLfWa2J7DaZYD+kJtihraAsnIKxCJ5AJTYFhQMx OtVoQOorkaUWiypXnixuSEG9ZZei9pVO/hw8HW7V92+hjBVhzay8s/SxrlVJ7Fg8BW yc7EQ+VZm0fv9sCjGxVVpn7a7C+bxHz1Ar66Mxo6F3MFZLD7me9ODG5CI1iLGvYa5O heewzlx9InG5A== Received: by keithp.com (Postfix, from userid 1000) id 765121E6013A; Fri, 3 Sep 2021 23:09:10 -0700 (PDT) From: Keith Packard To: linux-kernel@vger.kernel.org Cc: Abbott Liu , Alexander Sverdlin , Andrew Morton , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , Bjorn Andersson , Florian Fainelli , Geert Uytterhoeven , Hartley Sweeten , Jens Axboe , Jian Cai , Joe Perches , Kees Cook , Keith Packard , Krzysztof Kozlowski , Linus Walleij , linux-arm-kernel@lists.infradead.org, Manivannan Sadhasivam , Marc Zyngier , Masahiro Yamada , Miguel Ojeda , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Nicolas Pitre , Rob Herring , Russell King , Thomas Gleixner , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Valentin Schneider , Viresh Kumar , "Wolfram Sang (Renesas)" , YiFei Zhu , Keith Packard Subject: [PATCH 0/2] ARM: support THREAD_INFO_IN_TASK (v7 only) (v2) Date: Fri, 3 Sep 2021 23:09:05 -0700 Message-Id: <20210904060908.1310204-1-keithp@keithp.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210902155429.3987201-1-keithp@keithp.com> References: <20210902155429.3987201-1-keithp@keithp.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210903_230917_927470_4EDEEF4F X-CRM114-Status: GOOD ( 16.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Placing thread_info in the kernel stack leaves it vulnerable to stack overflow attacks. This short series addresses that by using the existing THREAD_INFO_IN_TASK infrastructure. This is the second version of this series, in this version the changes are restricted to v7 hardware which offers a way to identify each cpu in the system without reference to the stack it is using. The series is broken into three pieces: 1) Change the secondary_start_kernel API to pass the cpu number to this function. This is required for the following patch because the raw_smp_processor_id() macro will use the per_cpu_offset value which needs to have the cpu number to get the right value. 2) Enable THREAD_INFO_IN_TASK by creating a new per-cpu variable, current_task, just like the x86 architecture. The largest changes are in the assembly code where fetching the current_task value requires a temporary register. Fortunately, each location in the code performing this had a reasonably obvious register to use. 3) Optimize access to the cpu number using another new per-cpu variable. This is not functionally necessary, but avoids de-referencing through two pointers at modest memory cost. Signed-off-by: Keith Packard _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel