Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp16641547ybl; Wed, 1 Jan 2020 09:58:07 -0800 (PST) X-Google-Smtp-Source: APXvYqw3BihcS1Fqfvmuk2PI8fLKXCiI0VmOQVjSacxMi96MAetEF+Qj/DhHqLLYgpz7Co9lZhcd X-Received: by 2002:a9d:5c8a:: with SMTP id a10mr52684622oti.95.1577901487315; Wed, 01 Jan 2020 09:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577901487; cv=none; d=google.com; s=arc-20160816; b=OJGehB/zXdIh+B2cXpMRXsxYW/vbTM6b6hfNrP8TkT0AsOEmgFhh13wUB8ruSR+lt+ iIkR50Wv8s7LNOiGiVK9QC8zFzBp+bFRrHe1vCkbSvrP6ekJI72zwWbNdiopRZyjBpQ2 FkEHZivxPv3WAyXcCC0PLEqLMjZgcCzjSkA775N20lo/z2tbBjzUVM7oHZ1ZNskDDFTe d/JKY8XcbkdV/Paus+us2c8/qxgeOm6ZO4AvaBpeOQK7soIjK8Bs65qKAsY0Pzi8XN+h GIeHdx2g2rYwsftQcoIR62INSoEyKnn5gxYMpMYrXKvHpO5ymIT8v1ThGz88ipEwV6he ZTBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bxdqVdO/ZL+zRgdpxmrLZZskW1wmCQ5oo+9ANDQKquo=; b=s9h112roMZoUBvmOTVRWnZx4g32bOEvsuPN3vPndap4oL23qEtkECzFd1e1F7cjdEu cVoZBBkbKNvXac6V034Y9upq9PxBVHnJnOYyFMhPDN4ly0f2jFqtBs2QKJedWm4mOJ+J blOGPHyGpZsl6zFaC1iJmca3YWMmeUSc+DRdAKODKtAUrpXyLfhmSd7GSuvy9l89BA5I xchIEeH0w97EFqA87h4hVSgJ0PIwdsBs4mHy9MKzf22YtKn5EEZfEJobWHrw9T7t936z VZHDihkJQUXxDNxfSI4hqvr1SklShB9V9NohI+BsXTaj+YzlynkQJZpeSZi/3hBv77SP 7SXA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11si24881941oib.246.2020.01.01.09.57.54; Wed, 01 Jan 2020 09:58:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727304AbgAAR5N (ORCPT + 99 others); Wed, 1 Jan 2020 12:57:13 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46880 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727237AbgAAR5N (ORCPT ); Wed, 1 Jan 2020 12:57:13 -0500 Received: by mail-pg1-f196.google.com with SMTP id z124so20815555pgb.13; Wed, 01 Jan 2020 09:57:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bxdqVdO/ZL+zRgdpxmrLZZskW1wmCQ5oo+9ANDQKquo=; b=RkfcffGvZM4B1Du++mQh+XQ87vFJ5sNSmkOCxH7yvIDeKeuzT85InDVScXwOExfHQc qj132xME9AzW+0fCu8giVjSHMCd0MJSqVS+Q+pDFVXlWUdSuOQHAvQvs44J+Sx8toSXN j/gvYkOSHN2w2HmEiWxjSeQb9BfU7TeyRt6rgrZZKCbIwoZcoA+jIPcweir7m3AaHKD3 U8071/qrJf6cLT4d+WS/65ajx4DzNb7EkevaxXFwQJ74vLJVW85//Hlu9/1YD+X9QJD9 U7ba1zu6Oyn0ORDSRqFCSV6ih06ld2P6Yl0EiVPUeGNbQ30Za64Lq0MGkJUrvlYn1Z1/ ylvA== X-Gm-Message-State: APjAAAUp5tH9yVi7PFDNlvItcCM+8dJusjEytseHbBa5f5xkNQjZxU1F XKrpgjpFKZJgO+x2H8JdWnZl2Gt5Cz+fQw== X-Received: by 2002:a65:48cb:: with SMTP id o11mr85941450pgs.313.1577901431976; Wed, 01 Jan 2020 09:57:11 -0800 (PST) Received: from localhost ([2601:646:8a00:9810:5af3:56d9:f882:39d4]) by smtp.gmail.com with ESMTPSA id o19sm8712565pjr.2.2020.01.01.09.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jan 2020 09:57:11 -0800 (PST) From: Paul Burton To: linux-mips@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Paul Burton , "Jason A. Donenfeld" , Arnd Bergmann , Christian Brauner , Vincenzo Frascino , stable@vger.kernel.org Subject: [PATCH] MIPS: Don't declare __current_thread_info globally Date: Wed, 1 Jan 2020 09:59:16 -0800 Message-Id: <20200101175916.558284-1-paulburton@kernel.org> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Declaring __current_thread_info as a global register variable has the effect of preventing GCC from saving & restoring its value in cases where the ABI would typically do so. To quote GCC documentation: > If the register is a call-saved register, call ABI is affected: the > register will not be restored in function epilogue sequences after the > variable has been assigned. Therefore, functions cannot safely return > to callers that assume standard ABI. When our position independent VDSO is built for the n32 or n64 ABIs all functions it exposes should be preserving the value of $gp/$28 for their caller, but in the presence of the __current_thread_info global register variable GCC stops doing so & simply clobbers $gp/$28 when calculating the address of the GOT. In cases where the VDSO returns success this problem will typically be masked by the caller in libc returning & restoring $gp/$28 itself, but that is by no means guaranteed. In cases where the VDSO returns an error libc will typically contain a fallback path which will now fail (typically with a bad memory access) if it attempts anything which relies upon the value of $gp/$28 - eg. accessing anything via the GOT. Fix this by moving the declaration of __current_thread_info inside the current_thread_info() function, demoting it from global register variable to local register variable & avoiding inadvertently creating a non-standard calling ABI for the VDSO. Signed-off-by: Paul Burton Reported-by: "Jason A. Donenfeld" Fixes: ebb5e78cc634 ("MIPS: Initial implementation of a VDSO") Cc: Arnd Bergmann Cc: Christian Brauner Cc: Vincenzo Frascino Cc: # v4.4+ --- arch/mips/include/asm/thread_info.h | 4 ++-- arch/mips/kernel/relocate.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h index 4993db40482c..aceefc3f9a1a 100644 --- a/arch/mips/include/asm/thread_info.h +++ b/arch/mips/include/asm/thread_info.h @@ -50,10 +50,10 @@ struct thread_info { } /* How to get the thread information struct from C. */ -register struct thread_info *__current_thread_info __asm__("$28"); - static inline struct thread_info *current_thread_info(void) { + register struct thread_info *__current_thread_info __asm__("$28"); + return __current_thread_info; } diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c index 3d80a51256de..c9afdc39b003 100644 --- a/arch/mips/kernel/relocate.c +++ b/arch/mips/kernel/relocate.c @@ -296,6 +296,7 @@ static inline int __init relocation_addr_valid(void *loc_new) void *__init relocate_kernel(void) { + register struct thread_info *__current_thread_info __asm__("$28"); void *loc_new; unsigned long kernel_length; unsigned long bss_length; -- 2.24.0