Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1615555ybp; Fri, 11 Oct 2019 17:38:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6mWZwCeaWP28rCoZja3EGLFB0k716J1x2PeaQSXfMzH8ZHwI4dfYdcdnGuLyb06132115 X-Received: by 2002:a17:906:f42:: with SMTP id h2mr16659490ejj.39.1570840682573; Fri, 11 Oct 2019 17:38:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570840682; cv=none; d=google.com; s=arc-20160816; b=x9tZvKKdKQ4oDdOJ6LdPqlFssMMUuZQCXKWny/ck9jyNcliB1j8WFjzIjLukevKmOA xXbkcktl0H5dD5oBMf7mNtGh87vxXNlweW6H/iWSZeqxAU7GJFQ5Fob3q6B39hk/NBq+ HH2sXBJGZDBUZel8mWA6EpJDJ4nc5rza3GpykRL/iPaUsUTTjwIj5Ee3+Xizh20YJ8Ae s0pccE25CeUbrlDqeN/AXnhZFjB8x/zaxMQ3hcgFAbI00Pn+vf+8TZzB0EO3cxXsFtrS oOhyOWGL+umvvUxGv/ZXCjXJB+tkmMyfC4y3IR98p7XS+Q2ULOpVDsG+t1IEUTqCCtP3 GK3w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KOU51IFsj1iWUWTwrZgYX0bBua/cZqGBz0E2pjuMMik=; b=NKD1k8Rhb7xRWu9bO5IU0plJ8d+aWOwBWQLkFt6Sop2zv+ohppb9mdtQnbIh1nzxp7 jgOzOZyeDT4HVYwIvPelwS0xE5uag1WqRBsydOGU88s09Wj8uiggjgM/ZTvhWWueS57k JeMVwQIWhqjNLo4VBR07qi5KpXkxyes1KiArvdnda9sAe2oQxxN3AIguByvtk8uxgDZm 6kjsq9qonAudaN+28cU674wdSzRmMZHzWLiksFJ9ow8KG4mIhG8dRjTYU5MVvhFjb8Pd lBQm1FpDpGgTOQsUKBJ+ogBhWZOjjqTvSdG773Vt7DP4+XKa6Gw1DR3hAoILXFNrnlgI ffZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UTJP5c51; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z22si6234331eji.413.2019.10.11.17.37.39; Fri, 11 Oct 2019 17:38:02 -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=@gmail.com header.s=20161025 header.b=UTJP5c51; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727953AbfJLAhb (ORCPT + 99 others); Fri, 11 Oct 2019 20:37:31 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:45065 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726345AbfJLAha (ORCPT ); Fri, 11 Oct 2019 20:37:30 -0400 Received: by mail-lf1-f67.google.com with SMTP id r134so8197779lff.12 for ; Fri, 11 Oct 2019 17:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KOU51IFsj1iWUWTwrZgYX0bBua/cZqGBz0E2pjuMMik=; b=UTJP5c51u97TZQgmSLoRxAc925Tkumx8EJcmpN2Qa463ReM1bWUp4aN9rj4Wo8FsfU 19TbDGA3FzoulgBqb/PHvZtLhF0VqxWCVzjh+aju5wXruPSLQFPp8TKPQn2j3y43lLvR /ML1Y+T3xSkUA7U3uRn/a4eihlQ3sOFHA8kWUGTrMJIVVIszwHEx3VyMY71qjM/p4ggy ofLUpySc3mRtQYwcolnmzLyVEhvtu6n6vqUpfIuY/6zfiLtRZyHxIbrxLQqTf3E50p7a ce3FP1VdZICSAfhGh7+Cl3B0M7f6I5DKs8lNG574GxL+KO0twj3+ZjcjOb7C4khywNUR 9IZA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=KOU51IFsj1iWUWTwrZgYX0bBua/cZqGBz0E2pjuMMik=; b=kNwN3ZtRsWNTtDqmhFWRN26F4uaJIzu5DNdnxLUJZix94qIZ9f9unfpynOWXQYddn4 n1h3N/VhsOoOx1BP5PactCZMbrqfZGXSTXMoBzGhM4HhhVwG5nhgXh3twe0gJY/fzYzx YTW49V2upg0alvneT+/4xPVixMh/t0Ev3EKgRyAlwaqqFYseFv1BM0jxEsflZEfxeKMn R2NqRs4CN571+2eAC82YRJVtIXA97LPV0QHSkDI+8xZOHK6lS15fDnWotxKcy8tpxccv qeli35PAvZ4X18a5cYRei03AkXljpwfuyif3OlRfzGimP4972lGevxBuB6W3MqoizuLj W4Lg== X-Gm-Message-State: APjAAAUjwcUls+dadpiqluoRrWaGQxKrQZMiODDQi/W+pWUkaDIXCzQ1 eDY053j/Gcsvhz9gvJCxSUk= X-Received: by 2002:ac2:5bc1:: with SMTP id u1mr10487452lfn.182.1570840648861; Fri, 11 Oct 2019 17:37:28 -0700 (PDT) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id f22sm2346620lfa.41.2019.10.11.17.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 17:37:28 -0700 (PDT) From: Max Filippov To: linux-xtensa@linux-xtensa.org, Al Viro Cc: Chris Zankel , linux-kernel@vger.kernel.org, Max Filippov Subject: [PATCH v2 1/4] xtensa: fix {get,put}_user() for 64bit values Date: Fri, 11 Oct 2019 17:37:05 -0700 Message-Id: <20191012003708.22182-2-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191012003708.22182-1-jcmvbkbc@gmail.com> References: <20191012003708.22182-1-jcmvbkbc@gmail.com> 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 From: Al Viro First of all, on short copies __copy_{to,from}_user() return the amount of bytes left uncopied, *not* -EFAULT. get_user() and put_user() are expected to return -EFAULT on failure. Another problem is get_user(v32, (__u64 __user *)p); that should fetch 64bit value and the assign it to v32, truncating it in process. Current code, OTOH, reads 8 bytes of data and stores them at the address of v32, stomping on the 4 bytes that follow v32 itself. Signed-off-by: Al Viro Signed-off-by: Max Filippov --- arch/xtensa/include/asm/uaccess.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/xtensa/include/asm/uaccess.h b/arch/xtensa/include/asm/uaccess.h index 6792928ba84a..f568c00392ec 100644 --- a/arch/xtensa/include/asm/uaccess.h +++ b/arch/xtensa/include/asm/uaccess.h @@ -100,7 +100,7 @@ do { \ case 4: __put_user_asm(x, ptr, retval, 4, "s32i", __cb); break; \ case 8: { \ __typeof__(*ptr) __v64 = x; \ - retval = __copy_to_user(ptr, &__v64, 8); \ + retval = __copy_to_user(ptr, &__v64, 8) ? -EFAULT : 0; \ break; \ } \ default: __put_user_bad(); \ @@ -198,7 +198,16 @@ do { \ case 1: __get_user_asm(x, ptr, retval, 1, "l8ui", __cb); break;\ case 2: __get_user_asm(x, ptr, retval, 2, "l16ui", __cb); break;\ case 4: __get_user_asm(x, ptr, retval, 4, "l32i", __cb); break;\ - case 8: retval = __copy_from_user(&x, ptr, 8); break; \ + case 8: { \ + u64 __x; \ + if (unlikely(__copy_from_user(&__x, ptr, 8))) { \ + retval = -EFAULT; \ + (x) = 0; \ + } else { \ + (x) = *(__force __typeof__((ptr)))&__x; \ + } \ + break; \ + } \ default: (x) = __get_user_bad(); \ } \ } while (0) -- 2.20.1