Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3019716pxb; Mon, 18 Oct 2021 06:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqy0GFEZt1OqgDya81g/NuqsbM4Xpy+9CM+qfsfUZC9ExmgZbzmsXg8r0Wtd9hcj65GHuH X-Received: by 2002:a17:90b:1d0a:: with SMTP id on10mr33773150pjb.218.1634564659772; Mon, 18 Oct 2021 06:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634564659; cv=none; d=google.com; s=arc-20160816; b=UdZjKJO1/TxaAu7NlJndPpiTEuVZSc5srddiY59NDURITAkBqsIzLrHUyn5ABHKL25 3jgI2G8HV7z1Fffb/jks49Sy2KdBm7wpetBPtk/8ZheA72dKCgN9HguG4fILwVNx7+8k uaEqFlCs47c3bxxOqzq86jTtBHHDCeixUTYyXuzoS1CZ5B7tGvbjr3geetjR0NQkvZ2F 5EKJ2OmlVza4k2mz0g/8HPa+7cw8B9ZJBSrqFMkgiPTzLZyUR3+Vd3OE/ub7MXKp+acK DkLwJAPRYIfxDurkpeMry7agH9BEgjaZRx097OVfeYk/8APwL7iBSexjZzdwupoyKiez t0CQ== 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=r+GTp00r5+4tsmleyGl5Pwr19mqe8g16ba33Q97Cyl8=; b=sGNp5bozB7A9WprVXswVNiej1+UqFLWxD+8nVl7Aolpk0agEkFPp8SNIXl2f7f/Pk8 T39gvoOkbSKkfpDc1w5W+/ZZ41RfCwHVqe0lF96iUJcX/i5sIAgshjY2Q6vbN4n3qeNZ jw6ImopYooLhwmb+wev4xJK6oeNhW3lw38Q3rTnqlFp08h9S4z7OKi0PkXxp2/fF9uY8 aP0qcHaBTIK9zB44uHjg3CHYizuCkLVYopgVL+yNwqOXjAXuVfxIqlgbwK1zm4239E6R BrOGh9hLv1JhogZukRIUSgsaSavPoQ3kWtYkteJEhntJwYqnRnE8vymg2Kem69UCwEdL q3GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L7biSQsI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pf3si25749983pjb.53.2021.10.18.06.44.06; Mon, 18 Oct 2021 06:44:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=L7biSQsI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232759AbhJRNoh (ORCPT + 99 others); Mon, 18 Oct 2021 09:44:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:40222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233363AbhJRNmn (ORCPT ); Mon, 18 Oct 2021 09:42:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1D2F861439; Mon, 18 Oct 2021 13:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634564056; bh=tKdSaJ4ky4rkcucRDq96qoY0E2exYgCClISb3PmPDUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L7biSQsIXLf2t8nmBx1dD3GDvFFGcxKdjgRKsks1SzPGZj47WCZfF1NCiudXUiCJb wndu0J4MKBITHEGjS+sflkCEMh13CCH7GC+KosbacfrecipjKFhkq3liXAaCjJdm5V EMRqhcMN/KVPwBI7cvwOwqjkiAAw+uqORXCuERtY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Guo Ren Subject: [PATCH 5.10 015/103] csky: dont let sigreturn play with priveleged bits of status register Date: Mon, 18 Oct 2021 15:23:51 +0200 Message-Id: <20211018132335.209394743@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018132334.702559133@linuxfoundation.org> References: <20211018132334.702559133@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro commit fbd63c08cdcca5fb1315aca3172b3c9c272cfb4f upstream. csky restore_sigcontext() blindly overwrites regs->sr with the value it finds in sigcontext. Attacker can store whatever they want in there, which includes things like S-bit. Userland shouldn't be able to set that, or anything other than C flag (bit 0). Do the same thing other architectures with protected bits in flags register do - preserve everything that shouldn't be settable in user mode, picking the rest from the value saved is sigcontext. Signed-off-by: Al Viro Signed-off-by: Guo Ren Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- arch/csky/kernel/signal.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/arch/csky/kernel/signal.c +++ b/arch/csky/kernel/signal.c @@ -52,10 +52,14 @@ static long restore_sigcontext(struct pt struct sigcontext __user *sc) { int err = 0; + unsigned long sr = regs->sr; /* sc_pt_regs is structured the same as the start of pt_regs */ err |= __copy_from_user(regs, &sc->sc_pt_regs, sizeof(struct pt_regs)); + /* BIT(0) of regs->sr is Condition Code/Carry bit */ + regs->sr = (sr & ~1) | (regs->sr & 1); + /* Restore the floating-point state. */ err |= restore_fpu_state(sc);