Received: by 10.192.165.148 with SMTP id m20csp2447152imm; Sun, 22 Apr 2018 07:15:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/iExRLPdErJ+TGjrs41bsh4P2/fLx0rtMoE7FzNL+ZDSMDsDeBPH+GYDu6AAy15bpB65eo X-Received: by 2002:a17:902:bf41:: with SMTP id u1-v6mr13120668pls.257.1524406537213; Sun, 22 Apr 2018 07:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406537; cv=none; d=google.com; s=arc-20160816; b=m/XQl9fK6i6/hAvPvmlznMxeUBm+lEqgvNDr0fh5lS7xOYcvXYzgvYWcoWZiDDGwW6 dO5WKzteAavDilT69HVR+9Lpr3dbTreqzyGRrIAE68/77u4YbEP7BiM43q9CVZtHeb78 WTLLjethG9TEAk56+0pidTG651U4cBdCtaRjRRMGjWheSL6G+YNA6ee5vrH6YFfr3Xh2 gUfd+sEBg7RInMKp8fbXtt1473BP87jDdBtjU5PLS+T6LLytftYExEwB6pU103KRbP88 dO9cQD2Lh+BzEIxxu5lDf/Zq0eeXhtaSqijOKyzqCJxSsMvsEwaaKTUGIPCftOFFVQ4s 4dxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=on2oWJfh21TiS7RFPkvqLGctsQvjwfPp0qYd/sGsGAI=; b=VpWEnFiY3ZWuejmsbU1uFfa6UBMGM/1bN8Kp69kmVx/OxEE/mkKdEWWQ3rlkK3YNN5 MOlCDHQUl/smWb4YarVVb9taAv9PVBp39OOKIdpOWxWqq953I8egLFzMvHx/h2Wn+TNR xkqViFN4OpaPyCPM7eD3ajvzjhHPOy/4QmCCo1ZfXOkmOMBflM+3ahzABLQA4qfuJSK+ BEKGFmjo4gq7haTEUxm9SXOsca+bP1ion+e196f/Rw6Fo5Y8jpDHStfoDtCf8CQ9L8Ah w3QUqrkdkTl9rywqnYSHfzC1jMn6invOIZ1pczHrltabRK9sAv7I+MJOLgO/GMPR/2SF //OQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si7927024pgs.538.2018.04.22.07.15.22; Sun, 22 Apr 2018 07:15:37 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757011AbeDVOO2 (ORCPT + 99 others); Sun, 22 Apr 2018 10:14:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56398 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756977AbeDVOOZ (ORCPT ); Sun, 22 Apr 2018 10:14:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id AB0775AD; Sun, 22 Apr 2018 14:14:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Hogan , Matt Redfearn , Ralf Baechle , linux-mips@linux-mips.org Subject: [PATCH 4.9 81/95] MIPS: memset.S: Fix return of __clear_user from Lpartial_fixup Date: Sun, 22 Apr 2018 15:53:50 +0200 Message-Id: <20180422135213.740637068@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Matt Redfearn commit daf70d89f80c6e1772233da9e020114b1254e7e0 upstream. The __clear_user function is defined to return the number of bytes that could not be cleared. From the underlying memset / bzero implementation this means setting register a2 to that number on return. Currently if a page fault is triggered within the memset_partial block, the value loaded into a2 on return is meaningless. The label .Lpartial_fixup\@ is jumped to on page fault. In order to work out how many bytes failed to copy, the exception handler should find how many bytes left in the partial block (andi a2, STORMASK), add that to the partial block end address (a2), and subtract the faulting address to get the remainder. Currently it incorrectly subtracts the partial block start address (t1), which has additionally been clobbered to generate a jump target in memset_partial. Fix this by adding the block end address instead. This issue was found with the following test code: int j, k; for (j = 0; j < 512; j++) { if ((k = clear_user(NULL, j)) != j) { pr_err("clear_user (NULL %d) returned %d\n", j, k); } } Which now passes on Creator Ci40 (MIPS32) and Cavium Octeon II (MIPS64). Suggested-by: James Hogan Signed-off-by: Matt Redfearn Cc: Ralf Baechle Cc: linux-mips@linux-mips.org Cc: stable@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/19108/ Signed-off-by: James Hogan Signed-off-by: Greg Kroah-Hartman --- arch/mips/lib/memset.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/mips/lib/memset.S +++ b/arch/mips/lib/memset.S @@ -251,7 +251,7 @@ PTR_L t0, TI_TASK($28) andi a2, STORMASK LONG_L t0, THREAD_BUADDR(t0) - LONG_ADDU a2, t1 + LONG_ADDU a2, a0 jr ra LONG_SUBU a2, t0