Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp599774img; Fri, 22 Mar 2019 04:55:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwg4ypS1C1YKKI3scE8jjgK1+bdJht+EQzV7Gc2dEISHGBs1rtI47t6nwp7Iy4keFiSub7F X-Received: by 2002:a63:2bc6:: with SMTP id r189mr8258149pgr.201.1553255736683; Fri, 22 Mar 2019 04:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553255736; cv=none; d=google.com; s=arc-20160816; b=Z/wtQA5Uu8ROEnbB0Y8hHjYh3uEGezgkg20yhIFBWjhaHJp34C21Nr7QSZqdsNQBbU J4gyjvB549vxi0WKqfOJdFw25/vaHLfnJpR5b6QXh/lJYIy5sc3EDmMB8J2aX1aDAGaf JhDEwJNnF1WG1YMb1KwkPXBYAYhqEdc/EpyHXuehW7UAcLp7myO/MxOEo9c1A9CwTj+6 SFWVPNocLcpJHmthGVu486u5iVdTBO4qvZkg9nQ5VsVKJeVS8/AoNQq6FfFsis7tth4q EZk2PGht9R2FiDsSQNh6h+KkvqfO1JQaZp+hqtEON4wmXgVEgacoKAWximU5xlvwfqYM sxKg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AT8o8yvF3Hy2u3Py2V+cnabrn1m2FIz8VLcYLfXpFsU=; b=ty2xhOYg0uj7Y5OyhCr/BQnD/8Lx6hvdWw2A1ateN+VTkAOwQLxGWmhXYLkL4AfJH+ NW26WUIPp3bEzHo9qi9s/BKwcW+WuMT1oNzooIBpYEvTjiGOD9xDiUu0/h5a6sjsWw6n BOn5arB2KFiVxIxrCTHsvD+v4YA68Hf2aKzNNqNr4sDc4qZZ9HIcJ2pu0TFxeqC0d/Gq mqIjXn/9DOm4La7DiclCrsQjxgGyovtEKJpcjhu5hAsEfBPT9t7GF9EfDU390ThqEMuT o7zT/eQ5msetgoj3rJMsl+V/GQHzM4c76kesjExbQSNUGb3aMGc9BrlaGmjCb4qtULdf 4Bug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ntKJ01qW; 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 g64si6619582pfd.234.2019.03.22.04.55.21; Fri, 22 Mar 2019 04:55:36 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ntKJ01qW; 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 S1732865AbfCVLxb (ORCPT + 99 others); Fri, 22 Mar 2019 07:53:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:57692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732221AbfCVLxa (ORCPT ); Fri, 22 Mar 2019 07:53:30 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A1B020850; Fri, 22 Mar 2019 11:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255609; bh=pN/A+MOnhI3ujxG9a6UmmFozemMJhARZgwYxSjjQcTQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ntKJ01qWzgg4Po10fHHLNP9REW7VqNdmfC52fJ/aArBAvVgaekAz0hhI37jvDDWk4 kCr3oP/zZJFy27wpNQzetc3Z2JgVmLGZuIAzCCgJews34AFCGyaboY/rgVHMgKy/c0 AawHpabV5I+LuO8iMpzX9hCMO4HG3Qjwdj6LwtGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Meelis Roos , Mathieu Malaterre , Michael Ellerman Subject: [PATCH 4.14 143/183] powerpc/ptrace: Simplify vr_get/set() to avoid GCC warning Date: Fri, 22 Mar 2019 12:16:11 +0100 Message-Id: <20190322111252.136172126@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111241.819468003@linuxfoundation.org> References: <20190322111241.819468003@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Ellerman commit ca6d5149d2ad0a8d2f9c28cbe379802260a0a5e0 upstream. GCC 8 warns about the logic in vr_get/set(), which with -Werror breaks the build: In function ‘user_regset_copyin’, inlined from ‘vr_set’ at arch/powerpc/kernel/ptrace.c:628:9: include/linux/regset.h:295:4: error: ‘memcpy’ offset [-527, -529] is out of the bounds [0, 16] of object ‘vrsave’ with type ‘union ’ [-Werror=array-bounds] arch/powerpc/kernel/ptrace.c: In function ‘vr_set’: arch/powerpc/kernel/ptrace.c:623:5: note: ‘vrsave’ declared here } vrsave; This has been identified as a regression in GCC, see GCC bug 88273. However we can avoid the warning and also simplify the logic and make it more robust. Currently we pass -1 as end_pos to user_regset_copyout(). This says "copy up to the end of the regset". The definition of the regset is: [REGSET_VMX] = { .core_note_type = NT_PPC_VMX, .n = 34, .size = sizeof(vector128), .align = sizeof(vector128), .active = vr_active, .get = vr_get, .set = vr_set }, The end is calculated as (n * size), ie. 34 * sizeof(vector128). In vr_get/set() we pass start_pos as 33 * sizeof(vector128), meaning we can copy up to sizeof(vector128) into/out-of vrsave. The on-stack vrsave is defined as: union { elf_vrreg_t reg; u32 word; } vrsave; And elf_vrreg_t is: typedef __vector128 elf_vrreg_t; So there is no bug, but we rely on all those sizes lining up, otherwise we would have a kernel stack exposure/overwrite on our hands. Rather than relying on that we can pass an explict end_pos based on the sizeof(vrsave). The result should be exactly the same but it's more obviously not over-reading/writing the stack and it avoids the compiler warning. Reported-by: Meelis Roos Reported-by: Mathieu Malaterre Cc: stable@vger.kernel.org Tested-by: Mathieu Malaterre Tested-by: Meelis Roos Signed-off-by: Michael Ellerman Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/ptrace.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -547,6 +547,7 @@ static int vr_get(struct task_struct *ta /* * Copy out only the low-order word of vrsave. */ + int start, end; union { elf_vrreg_t reg; u32 word; @@ -555,8 +556,10 @@ static int vr_get(struct task_struct *ta vrsave.word = target->thread.vrsave; + start = 33 * sizeof(vector128); + end = start + sizeof(vrsave); ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave, - 33 * sizeof(vector128), -1); + start, end); } return ret; @@ -594,6 +597,7 @@ static int vr_set(struct task_struct *ta /* * We use only the first word of vrsave. */ + int start, end; union { elf_vrreg_t reg; u32 word; @@ -602,8 +606,10 @@ static int vr_set(struct task_struct *ta vrsave.word = target->thread.vrsave; + start = 33 * sizeof(vector128); + end = start + sizeof(vrsave); ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave, - 33 * sizeof(vector128), -1); + start, end); if (!ret) target->thread.vrsave = vrsave.word; }