From patchwork Wed Dec 11 15:05:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181230 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp903484och; Wed, 11 Dec 2019 07:12:34 -0800 (PST) X-Google-Smtp-Source: APXvYqyVfSf4Y8VQCFHeAMLwUNtmoxZIKHzhzs40ZVRTwbkY15CXaharAX/1Gze2jL6x1nE1UOiz X-Received: by 2002:a9d:74c7:: with SMTP id a7mr2705307otl.7.1576077154090; Wed, 11 Dec 2019 07:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077154; cv=none; d=google.com; s=arc-20160816; b=XHzjxQ3Gt5I/vac22U0A2VsYO6FOuEugBxCMph4egO0ArL4hnnWoUL84C8s4tv1ipH BHdfsFtUaSlFRgC9KqLlTB6I5utiDXMlksd6CoU3E3atomQsXehOjC9TW92yCnGf45X6 JE2iXsSvaSZ3YsUrQ+dQfHvsrLMD8+asvTzeyJoP2HvYyH933dr2oqVCYD+2eS1Nkyp4 a6cmGrmryBcSKMqY6SbwyMM2EFYRDHC++Dhl3xTkc3C2Ast3IkGvSR506GVdEsqdzK3K ZZx084Zg7OLW0GQEIxyVA3eniJDh7A4UiZGgufrAoTbA0ag9MImoXGOIxFykeX4scipq U/Cw== 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=yKiLlalyiYJuX0VuOkvU/CMGm/JBbRHRUKdry9rOx84=; b=i+QUmKnllTrNdBTcKepxr/dF/U4YO62+5JiUtIZDnPCA+/6rdGmvAjmqazY+KqfE9f UOSn1B0Wt5VAhIOQB19IbCIBlLW1ikUPXV4Pv+mfOyZEEzOk0hxWSnefl41n1OMHf3Fs 3CgdozM/gUFvhPCpR3CfJQYuI7aeQ6wHaXpfKy2EytKmBoJ/bmtZJCBNJY/GZ388nuAZ vPS+nLo6YBW+2NKLRFqnwcflOOvq1sYvWbTjuaUljNFrBXNYq3TZu5wtXw1QhRugezMt 431+tlpM7S7YoKAaibwOP5kSDam0KTqUH1hw4t1B9aDTJ41UwWBoqeoCjcaK8UbltXZL knJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2b0Q2Nu5; 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 a127si1314842oif.81.2019.12.11.07.12.33; Wed, 11 Dec 2019 07:12:34 -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; dkim=pass header.i=@kernel.org header.s=default header.b=2b0Q2Nu5; 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 S1731170AbfLKPMc (ORCPT + 27 others); Wed, 11 Dec 2019 10:12:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:33634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731083AbfLKPMS (ORCPT ); Wed, 11 Dec 2019 10:12:18 -0500 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 8F5DD2465B; Wed, 11 Dec 2019 15:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077137; bh=zQiU5dKwHOVRXTN0rVnNamHfzml94EObSwNzq6VHy0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2b0Q2Nu52JuT65VBZPg33Y7Sx7jY9EENYN4Xcs3d7aJqS4uJrrBJ62Xf/aLhOzd4e PtYShHhLtEiW3cXP4tVODnSNi4kKcM13ZfeVa20O/oUvnhwoudM+gc6dDsLgMvZixd g0DZFcj8hmIuTtncqm9KU7ZpBtozBzFBGnsHWNQ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vincent Guittot , "Peter Zijlstra (Intel)" , Linus Torvalds , Thomas Gleixner , dietmar.eggemann@arm.com, dsmythies@telus.net, juri.lelli@redhat.com, mgorman@suse.de, rostedt@goodmis.org, Ingo Molnar , Sasha Levin Subject: [PATCH 5.3 030/105] sched/pelt: Fix update of blocked PELT ordering Date: Wed, 11 Dec 2019 16:05:19 +0100 Message-Id: <20191211150230.499055068@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vincent Guittot [ Upstream commit b90f7c9d2198d789709390280a43e0a46345682b ] update_cfs_rq_load_avg() can call cpufreq_update_util() to trigger an update of the frequency. Make sure that RT, DL and IRQ PELT signals have been updated before calling cpufreq. Signed-off-by: Vincent Guittot Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: dietmar.eggemann@arm.com Cc: dsmythies@telus.net Cc: juri.lelli@redhat.com Cc: mgorman@suse.de Cc: rostedt@goodmis.org Fixes: 371bf4273269 ("sched/rt: Add rt_rq utilization tracking") Fixes: 3727e0e16340 ("sched/dl: Add dl_rq utilization tracking") Fixes: 91c27493e78d ("sched/irq: Add IRQ utilization tracking") Link: https://lkml.kernel.org/r/1572434309-32512-1-git-send-email-vincent.guittot@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 649c6b60929e2..ba7cc68a39935 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7530,6 +7530,19 @@ static void update_blocked_averages(int cpu) rq_lock_irqsave(rq, &rf); update_rq_clock(rq); + /* + * update_cfs_rq_load_avg() can call cpufreq_update_util(). Make sure + * that RT, DL and IRQ signals have been updated before updating CFS. + */ + curr_class = rq->curr->sched_class; + update_rt_rq_load_avg(rq_clock_pelt(rq), rq, curr_class == &rt_sched_class); + update_dl_rq_load_avg(rq_clock_pelt(rq), rq, curr_class == &dl_sched_class); + update_irq_load_avg(rq, 0); + + /* Don't need periodic decay once load/util_avg are null */ + if (others_have_blocked(rq)) + done = false; + /* * Iterates the task_group tree in a bottom up fashion, see * list_add_leaf_cfs_rq() for details. @@ -7557,14 +7570,6 @@ static void update_blocked_averages(int cpu) done = false; } - curr_class = rq->curr->sched_class; - update_rt_rq_load_avg(rq_clock_pelt(rq), rq, curr_class == &rt_sched_class); - update_dl_rq_load_avg(rq_clock_pelt(rq), rq, curr_class == &dl_sched_class); - update_irq_load_avg(rq, 0); - /* Don't need periodic decay once load/util_avg are null */ - if (others_have_blocked(rq)) - done = false; - update_blocked_load_status(rq, !done); rq_unlock_irqrestore(rq, &rf); } @@ -7625,12 +7630,18 @@ static inline void update_blocked_averages(int cpu) rq_lock_irqsave(rq, &rf); update_rq_clock(rq); - update_cfs_rq_load_avg(cfs_rq_clock_pelt(cfs_rq), cfs_rq); + /* + * update_cfs_rq_load_avg() can call cpufreq_update_util(). Make sure + * that RT, DL and IRQ signals have been updated before updating CFS. + */ curr_class = rq->curr->sched_class; update_rt_rq_load_avg(rq_clock_pelt(rq), rq, curr_class == &rt_sched_class); update_dl_rq_load_avg(rq_clock_pelt(rq), rq, curr_class == &dl_sched_class); update_irq_load_avg(rq, 0); + + update_cfs_rq_load_avg(cfs_rq_clock_pelt(cfs_rq), cfs_rq); + update_blocked_load_status(rq, cfs_rq_has_blocked(cfs_rq) || others_have_blocked(rq)); rq_unlock_irqrestore(rq, &rf); } From patchwork Wed Dec 11 15:05:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181285 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp718325ile; Wed, 11 Dec 2019 07:58:47 -0800 (PST) X-Google-Smtp-Source: APXvYqyyUmxadQnbc3MurRAlZh8i3oNnApyfJPGHrgLeXFjJUyQ960SlJFHt+I4XWUWUdi19hCMn X-Received: by 2002:a9d:f61:: with SMTP id 88mr2696815ott.234.1576079927574; Wed, 11 Dec 2019 07:58:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079927; cv=none; d=google.com; s=arc-20160816; b=vLGYU1+TGUNgfnElH8bNKamJ2wF1mFxK19SNZcdMkfSiqXsvvYGIcWTznjrDjfkxvX FJI1cxQltrK9A9Mw7xSejUTFn7YQ1j9bwj7+9uIiwGWU0GalMt7axJ5au2a35SqQZEX+ YuslKrEEuRHbU7TRn8hl9on6sBMDf/vCr0ds/Xk8CrlaZF7s0Fw6roQFeanFsJKs2xjI OrlIjLdwg0XFZfAe44iSzjM/fG1jZW+OSPIyw65dgemjI6Gp22ExXZa0O9EGzRidALat 5uB5S+DYnMH4I1bK5WzO/hka1mGI5vghNbssYfSxxpPSn3aj+vsAe4xzLAEKZIaGQWZn 4cdw== 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=RjR81QkhQYv19sOxqFt1wMuPFOEIEZCYoCmWCgMMF6Y=; b=MhVNLv2dtnLNoB4Ue7jf5Gyc2NtsYjOlBEgxIgwQtfQn7IBG00BkWlMp0pRpqqPyMk rgOz/ejIVZuld0lhuqOTX2qCuoq4Eo2bv6jLwuMfBDtptliAeDb1avXQwALE0loB1AD2 UUnm3w21UD9SDxhi2XH/KBZvJ6PtCTmLs3Kbd1phJChLqZt+1GU7iP8mWEYrcpMwzCv5 0uZoJrUDQGASnFFMUFxS3jCRoxE4XYOFIGa8NVlRq3+eCPair9f+A/dMzZ5igNUqq8+s CHDwaka5DKbj9fBmfU5vHmh6Ww/3b6NgOKq5MGYTONWKHf5mDsqw8Ghn9IPrN3YdIqt1 iVRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GTz5S2Pk; 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 d199si1346123oib.226.2019.12.11.07.58.45; Wed, 11 Dec 2019 07:58:47 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GTz5S2Pk; 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 S1730975AbfLKPOP (ORCPT + 27 others); Wed, 11 Dec 2019 10:14:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:37134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731427AbfLKPNb (ORCPT ); Wed, 11 Dec 2019 10:13:31 -0500 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 E9B532465C; Wed, 11 Dec 2019 15:13:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077210; bh=cQnHYqMKMnTnO6m2mJKlDYRQy3IpoH92Ix9Topw/7fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GTz5S2PkPIGoHm4VgVL0v2LmKciuqpdkqfIeWRYqWCVbKxFdBsQGa9SZcBtuIjTo9 3VRd61r32l6gKnDeyMuM6/0VrJ/1E4jJwIQX3cOaKLc1a3KovTPh6jJfPgmrPUKpiD /ITU/WkHs2kf9yz89sz7XbYz5y/6aRkRXWtEifwY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Mathieu Poirier , Mike Leach Subject: [PATCH 5.3 059/105] coresight: etm4x: Fix input validation for sysfs. Date: Wed, 11 Dec 2019 16:05:48 +0100 Message-Id: <20191211150244.203826612@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Leach commit 2fe6899e36aa174abefd017887f9cfe0cb60c43a upstream. A number of issues are fixed relating to sysfs input validation:- 1) bb_ctrl_store() - incorrect compare of bit select field to absolute value. Reworked per ETMv4 specification. 2) seq_event_store() - incorrect mask value - register has two event values. 3) cyc_threshold_store() - must mask with max before checking min otherwise wrapped values can set illegal value below min. 4) res_ctrl_store() - update to mask off all res0 bits. Reviewed-by: Leo Yan Reviewed-by: Mathieu Poirier Signed-off-by: Mike Leach Fixes: a77de2637c9eb ("coresight: etm4x: moving sysFS entries to a dedicated file") Cc: stable # 4.9+ Signed-off-by: Mathieu Poirier Link: https://lore.kernel.org/r/20191104181251.26732-6-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/coresight/coresight-etm4x-sysfs.c | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) --- a/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c +++ b/drivers/hwtracing/coresight/coresight-etm4x-sysfs.c @@ -655,10 +655,13 @@ static ssize_t cyc_threshold_store(struc if (kstrtoul(buf, 16, &val)) return -EINVAL; + + /* mask off max threshold before checking min value */ + val &= ETM_CYC_THRESHOLD_MASK; if (val < drvdata->ccitmin) return -EINVAL; - config->ccctlr = val & ETM_CYC_THRESHOLD_MASK; + config->ccctlr = val; return size; } static DEVICE_ATTR_RW(cyc_threshold); @@ -689,14 +692,16 @@ static ssize_t bb_ctrl_store(struct devi return -EINVAL; if (!drvdata->nr_addr_cmp) return -EINVAL; + /* - * Bit[7:0] selects which address range comparator is used for - * branch broadcast control. + * Bit[8] controls include(1) / exclude(0), bits[0-7] select + * individual range comparators. If include then at least 1 + * range must be selected. */ - if (BMVAL(val, 0, 7) > drvdata->nr_addr_cmp) + if ((val & BIT(8)) && (BMVAL(val, 0, 7) == 0)) return -EINVAL; - config->bb_ctrl = val; + config->bb_ctrl = val & GENMASK(8, 0); return size; } static DEVICE_ATTR_RW(bb_ctrl); @@ -1329,8 +1334,8 @@ static ssize_t seq_event_store(struct de spin_lock(&drvdata->spinlock); idx = config->seq_idx; - /* RST, bits[7:0] */ - config->seq_ctrl[idx] = val & 0xFF; + /* Seq control has two masks B[15:8] F[7:0] */ + config->seq_ctrl[idx] = val & 0xFFFF; spin_unlock(&drvdata->spinlock); return size; } @@ -1585,7 +1590,7 @@ static ssize_t res_ctrl_store(struct dev if (idx % 2 != 0) /* PAIRINV, bit[21] */ val &= ~BIT(21); - config->res_ctrl[idx] = val; + config->res_ctrl[idx] = val & GENMASK(21, 0); spin_unlock(&drvdata->spinlock); return size; } From patchwork Wed Dec 11 15:06:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181283 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp715360ile; Wed, 11 Dec 2019 07:55:56 -0800 (PST) X-Google-Smtp-Source: APXvYqxAQb9MP6Cp7KBfW65I8NeLwy0/GS5FD5hM4eX15TSsrfnbau6+UJxLETehRJSExLbA2oNt X-Received: by 2002:aca:cf58:: with SMTP id f85mr3411140oig.6.1576079756147; Wed, 11 Dec 2019 07:55:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576079756; cv=none; d=google.com; s=arc-20160816; b=Sca34yr6oKwDWwIDy15u+UB2jgfSwlKSU+FasERr3hrbmaEjd3z0Q1d5za9r5ZKbea 2Ve2uMIhZSK0sh8J2EYZ3tX0Z58jtoYAzePZfNXgBdRhEeS6psC4s2XKESpDepJIISrj agnez7o+uMrn6FmL8F8Sf+4uPjBKcOOEZbavSrAQil/x/FmZBhvF+DLlFvKRWvkSnqGM +7a8xVbL1jiOHjr0+Yhvsw/Z8JvC3dj1a5uZjI/FGipBMeiUWKGP0zLkTcbqqZRdXhwb xTyMmdbgy5kCl4+GnFPYIQ0UOuYdBTwn90HcIN9FlPNx3P2H7twXkwWH/BpH9OZWeBNf kHhg== 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=J5avmDOizACNmofqYuRE17p3bdRhlNoj/rXPF0Yd520=; b=BSYmPYfqQitlwfc6rUxGQlqZwk7FvA+RVRhziQlNMSHOMWqn4LnS8IQvcO5+NW1dPl YtVbU7YrRQQGwq7CwmktBhOkM+bnumnfGMuUmPmbxBSdp6BdR5Mj15MMc3s2CbnwAl9S Lf8fdoLahBa2Cg8RP9OkJxcB9VR0Y8OPvcYdUHzQx0yWI8ljmHPhL/KOMY8Z8/dgV/Uc 3XtXifuCFa/gs6Pv0CE17kIDBhcvXDvSFVUUED9g798ANAIwO2fMn1LmTwS9bzvdI0LB cKBER1LrG7al1tVRkhqAMUGA/wRP6MbA8HkZPtMxMsCbPb5yMRLhUEY1i4QpVUexYt6b LeLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=anJhU2U8; 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 f189si1471926oib.268.2019.12.11.07.55.55; Wed, 11 Dec 2019 07:55:56 -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; dkim=pass header.i=@kernel.org header.s=default header.b=anJhU2U8; 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 S1732426AbfLKPzy (ORCPT + 27 others); Wed, 11 Dec 2019 10:55:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:42098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731574AbfLKPPk (ORCPT ); Wed, 11 Dec 2019 10:15:40 -0500 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 05AFD20663; Wed, 11 Dec 2019 15:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077339; bh=KMskS2d1qc91r8quykui3HyZFlFhTsVOYc2Ir+Blyro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=anJhU2U8xL/Y0myzj6KDQCXlzLEW7Iyzh+DORgCbPBIsThOTPGsvG/SzgBVIpnEsX ZBZ/U+FEzQfQxoJzvVFE89jFqZn8DJGEX3DouH7EbiuMaWCR1C+JA31Le1Z/j9M9lm +bsyy+wvOVbuv6AUSk2LJPTjmhTUSE8+zkGlgqmw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Florian Bezdeka , Herbert Xu Subject: [PATCH 5.3 088/105] crypto: geode-aes - switch to skcipher for cbc(aes) fallback Date: Wed, 11 Dec 2019 16:06:17 +0100 Message-Id: <20191211150300.172484322@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit 504582e8e40b90b8f8c58783e2d1e4f6a2b71a3a upstream. Commit 79c65d179a40e145 ("crypto: cbc - Convert to skcipher") updated the generic CBC template wrapper from a blkcipher to a skcipher algo, to get away from the deprecated blkcipher interface. However, as a side effect, drivers that instantiate CBC transforms using the blkcipher as a fallback no longer work, since skciphers can wrap blkciphers but not the other way around. This broke the geode-aes driver. So let's fix it by moving to the sync skcipher interface when allocating the fallback. At the same time, align with the generic API for ECB and CBC by rejecting inputs that are not a multiple of the AES block size. Fixes: 79c65d179a40e145 ("crypto: cbc - Convert to skcipher") Cc: # v4.20+ ONLY Signed-off-by: Ard Biesheuvel Signed-off-by: Florian Bezdeka Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/geode-aes.c | 57 ++++++++++++++++++++++++++------------------- drivers/crypto/geode-aes.h | 2 - 2 files changed, 34 insertions(+), 25 deletions(-) --- a/drivers/crypto/geode-aes.c +++ b/drivers/crypto/geode-aes.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -166,13 +167,15 @@ static int geode_setkey_blk(struct crypt /* * The requested key size is not supported by HW, do a fallback */ - op->fallback.blk->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; - op->fallback.blk->base.crt_flags |= (tfm->crt_flags & CRYPTO_TFM_REQ_MASK); + crypto_sync_skcipher_clear_flags(op->fallback.blk, CRYPTO_TFM_REQ_MASK); + crypto_sync_skcipher_set_flags(op->fallback.blk, + tfm->crt_flags & CRYPTO_TFM_REQ_MASK); - ret = crypto_blkcipher_setkey(op->fallback.blk, key, len); + ret = crypto_sync_skcipher_setkey(op->fallback.blk, key, len); if (ret) { tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; - tfm->crt_flags |= (op->fallback.blk->base.crt_flags & CRYPTO_TFM_RES_MASK); + tfm->crt_flags |= crypto_sync_skcipher_get_flags(op->fallback.blk) & + CRYPTO_TFM_RES_MASK; } return ret; } @@ -181,33 +184,28 @@ static int fallback_blk_dec(struct blkci struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { - unsigned int ret; - struct crypto_blkcipher *tfm; struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm); + SYNC_SKCIPHER_REQUEST_ON_STACK(req, op->fallback.blk); - tfm = desc->tfm; - desc->tfm = op->fallback.blk; - - ret = crypto_blkcipher_decrypt_iv(desc, dst, src, nbytes); + skcipher_request_set_sync_tfm(req, op->fallback.blk); + skcipher_request_set_callback(req, 0, NULL, NULL); + skcipher_request_set_crypt(req, src, dst, nbytes, desc->info); - desc->tfm = tfm; - return ret; + return crypto_skcipher_decrypt(req); } + static int fallback_blk_enc(struct blkcipher_desc *desc, struct scatterlist *dst, struct scatterlist *src, unsigned int nbytes) { - unsigned int ret; - struct crypto_blkcipher *tfm; struct geode_aes_op *op = crypto_blkcipher_ctx(desc->tfm); + SYNC_SKCIPHER_REQUEST_ON_STACK(req, op->fallback.blk); - tfm = desc->tfm; - desc->tfm = op->fallback.blk; - - ret = crypto_blkcipher_encrypt_iv(desc, dst, src, nbytes); + skcipher_request_set_sync_tfm(req, op->fallback.blk); + skcipher_request_set_callback(req, 0, NULL, NULL); + skcipher_request_set_crypt(req, src, dst, nbytes, desc->info); - desc->tfm = tfm; - return ret; + return crypto_skcipher_encrypt(req); } static void @@ -307,6 +305,9 @@ geode_cbc_decrypt(struct blkcipher_desc struct blkcipher_walk walk; int err, ret; + if (nbytes % AES_BLOCK_SIZE) + return -EINVAL; + if (unlikely(op->keylen != AES_KEYSIZE_128)) return fallback_blk_dec(desc, dst, src, nbytes); @@ -339,6 +340,9 @@ geode_cbc_encrypt(struct blkcipher_desc struct blkcipher_walk walk; int err, ret; + if (nbytes % AES_BLOCK_SIZE) + return -EINVAL; + if (unlikely(op->keylen != AES_KEYSIZE_128)) return fallback_blk_enc(desc, dst, src, nbytes); @@ -366,9 +370,8 @@ static int fallback_init_blk(struct cryp const char *name = crypto_tfm_alg_name(tfm); struct geode_aes_op *op = crypto_tfm_ctx(tfm); - op->fallback.blk = crypto_alloc_blkcipher(name, 0, - CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK); - + op->fallback.blk = crypto_alloc_sync_skcipher(name, 0, + CRYPTO_ALG_NEED_FALLBACK); if (IS_ERR(op->fallback.blk)) { printk(KERN_ERR "Error allocating fallback algo %s\n", name); return PTR_ERR(op->fallback.blk); @@ -381,7 +384,7 @@ static void fallback_exit_blk(struct cry { struct geode_aes_op *op = crypto_tfm_ctx(tfm); - crypto_free_blkcipher(op->fallback.blk); + crypto_free_sync_skcipher(op->fallback.blk); op->fallback.blk = NULL; } @@ -420,6 +423,9 @@ geode_ecb_decrypt(struct blkcipher_desc struct blkcipher_walk walk; int err, ret; + if (nbytes % AES_BLOCK_SIZE) + return -EINVAL; + if (unlikely(op->keylen != AES_KEYSIZE_128)) return fallback_blk_dec(desc, dst, src, nbytes); @@ -450,6 +456,9 @@ geode_ecb_encrypt(struct blkcipher_desc struct blkcipher_walk walk; int err, ret; + if (nbytes % AES_BLOCK_SIZE) + return -EINVAL; + if (unlikely(op->keylen != AES_KEYSIZE_128)) return fallback_blk_enc(desc, dst, src, nbytes); --- a/drivers/crypto/geode-aes.h +++ b/drivers/crypto/geode-aes.h @@ -60,7 +60,7 @@ struct geode_aes_op { u8 *iv; union { - struct crypto_blkcipher *blk; + struct crypto_sync_skcipher *blk; struct crypto_cipher *cip; } fallback; u32 keylen; From patchwork Wed Dec 11 15:06:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181232 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp908005och; Wed, 11 Dec 2019 07:15:53 -0800 (PST) X-Google-Smtp-Source: APXvYqx6dkC2YrIlbap5aHFPRgAXh/CbB7qr/Jg+lwNQAGaBmou7Kv2MMr5kU5Scw6FYi6wsvF1d X-Received: by 2002:a05:6830:130d:: with SMTP id p13mr2711074otq.161.1576077353588; Wed, 11 Dec 2019 07:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077353; cv=none; d=google.com; s=arc-20160816; b=eQNq2RxOdFnGcnleuJSTFFSLGHMDr3IOA8LbPSnx4uckcuIM3MnEjMqFjY38zxSK6i RFxsPwDsJUHl2Br0UtT2+wZUlCQrSxshi6tI6DgNysftkqDlaqPSBB0XBkkMExZ9d4Dv /cwnvyj0c6JDhliMGv0iaM5IoRYFM6Mrgb3QSEumx4kzgWXkguWJu7u5osCvQxupSOW5 vmL/fxhhhFHUctXQEX2HKSu17ekVvIX4vusvRMtsoZeuhJHU9joOQH0f5GwRkUGgVwOR xcLHzbjadWAu28MjSV129R/JqxMRauUrlnz7hg6c5wTD21oR/pzgckGgfHSn1Mp+ibEE oD5g== 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=1eNYdp0bHxnbChS/dDVmlBoc5vA7lU7PvniHn9/QKJU=; b=Rpu8We1RiCakm2I+hfEfE393eOQXKygKWXp81w3r6xjfBw9C3DkDNjiq8EtJxOEwHr 24O9n48D4DaC1248tZmTP/h8jj4n0GhVwoKMMH4csz6Wb+XoExGCLYUptOkAc5ir52fN x1FJICUKoBVbJjm/Jt0H2fS9N/F1YZLWDSXQICILqhgwZJ22vfjuQO+Hq2iJW7iTaiDL itbAJ0CalWW7Os4O9x/5W4O776+L6XAZVni4D5RkBh8u2WiY3CTUkmZggKQ0i3WLATcD ZbQHasvewU4Zdy05S6kcGTEVMxmSHgPp78UYy+NvTLtxR10C0Qbs2g/tmGAZ9+5in2nH gaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VElkuX+X; 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 t28si1275776otr.16.2019.12.11.07.15.53; Wed, 11 Dec 2019 07:15:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=VElkuX+X; 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 S1731503AbfLKPPv (ORCPT + 27 others); Wed, 11 Dec 2019 10:15:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:42196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731413AbfLKPPm (ORCPT ); Wed, 11 Dec 2019 10:15:42 -0500 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 877F9208C3; Wed, 11 Dec 2019 15:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077341; bh=KOZ9Etup0eKMsSBgtIvUGGaM6PFOy51PmIQgKWiCYXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VElkuX+X1jhoAqhVUEeyVdiXI45FFHHVlLThEBuEd1f9JXIBzrQu9NsvxxwGhY9dy 9maFNWOlc/MJbrIOnZAe8Cxp5EUMsUELfdNPPdmv5y8Hn+2u3t5iuEGuerl2wTKE8+ JQ4TwUOSPxQvQH8SouLc9vwIhpee15B5PdQaFz6o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sahaj Sarup , Mark Salter , Gary R Hook , Herbert Xu Subject: [PATCH 5.3 089/105] crypto: ccp - fix uninitialized list head Date: Wed, 11 Dec 2019 16:06:18 +0100 Message-Id: <20191211150300.377604506@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Salter commit 691505a803a7f223b2af621848d581259c61f77d upstream. A NULL-pointer dereference was reported in fedora bz#1762199 while reshaping a raid6 array after adding a fifth drive to an existing array. [ 47.343549] md/raid:md0: raid level 6 active with 3 out of 5 devices, algorithm 2 [ 47.804017] md0: detected capacity change from 0 to 7885289422848 [ 47.822083] Unable to handle kernel read from unreadable memory at virtual address 0000000000000000 ... [ 47.940477] CPU: 1 PID: 14210 Comm: md0_raid6 Tainted: G W 5.2.18-200.fc30.aarch64 #1 [ 47.949594] Hardware name: AMD Overdrive/Supercharger/To be filled by O.E.M., BIOS ROD1002C 04/08/2016 [ 47.958886] pstate: 00400085 (nzcv daIf +PAN -UAO) [ 47.963668] pc : __list_del_entry_valid+0x2c/0xa8 [ 47.968366] lr : ccp_tx_submit+0x84/0x168 [ccp] [ 47.972882] sp : ffff00001369b970 [ 47.976184] x29: ffff00001369b970 x28: ffff00001369bdb8 [ 47.981483] x27: 00000000ffffffff x26: ffff8003b758af70 [ 47.986782] x25: ffff8003b758b2d8 x24: ffff8003e6245818 [ 47.992080] x23: 0000000000000000 x22: ffff8003e62450c0 [ 47.997379] x21: ffff8003dfd6add8 x20: 0000000000000003 [ 48.002678] x19: ffff8003e6245100 x18: 0000000000000000 [ 48.007976] x17: 0000000000000000 x16: 0000000000000000 [ 48.013274] x15: 0000000000000000 x14: 0000000000000000 [ 48.018572] x13: ffff7e000ef83a00 x12: 0000000000000001 [ 48.023870] x11: ffff000010eff998 x10: 00000000000019a0 [ 48.029169] x9 : 0000000000000000 x8 : ffff8003e6245180 [ 48.034467] x7 : 0000000000000000 x6 : 000000000000003f [ 48.039766] x5 : 0000000000000040 x4 : ffff8003e0145080 [ 48.045064] x3 : dead000000000200 x2 : 0000000000000000 [ 48.050362] x1 : 0000000000000000 x0 : ffff8003e62450c0 [ 48.055660] Call trace: [ 48.058095] __list_del_entry_valid+0x2c/0xa8 [ 48.062442] ccp_tx_submit+0x84/0x168 [ccp] [ 48.066615] async_tx_submit+0x224/0x368 [async_tx] [ 48.071480] async_trigger_callback+0x68/0xfc [async_tx] [ 48.076784] ops_run_biofill+0x178/0x1e8 [raid456] [ 48.081566] raid_run_ops+0x248/0x818 [raid456] [ 48.086086] handle_stripe+0x864/0x1208 [raid456] [ 48.090781] handle_active_stripes.isra.0+0xb0/0x278 [raid456] [ 48.096604] raid5d+0x378/0x618 [raid456] [ 48.100602] md_thread+0xa0/0x150 [ 48.103905] kthread+0x104/0x130 [ 48.107122] ret_from_fork+0x10/0x18 [ 48.110686] Code: d2804003 f2fbd5a3 eb03003f 54000320 (f9400021) [ 48.116766] ---[ end trace 23f390a527f7ad77 ]--- ccp_tx_submit is passed a dma_async_tx_descriptor which is contained in a ccp_dma_desc and adds it to a ccp channel's pending list: list_del(&desc->entry); list_add_tail(&desc->entry, &chan->pending); The problem is that desc->entry may be uninitialized in the async_trigger_callback path where the descriptor was gotten from ccp_prep_dma_interrupt which got it from ccp_alloc_dma_desc which doesn't initialize the desc->entry list head. So, just initialize the list head to avoid the problem. Cc: Reported-by: Sahaj Sarup Signed-off-by: Mark Salter Acked-by: Gary R Hook Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccp/ccp-dmaengine.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/crypto/ccp/ccp-dmaengine.c +++ b/drivers/crypto/ccp/ccp-dmaengine.c @@ -337,6 +337,7 @@ static struct ccp_dma_desc *ccp_alloc_dm desc->tx_desc.flags = flags; desc->tx_desc.tx_submit = ccp_tx_submit; desc->ccp = chan->ccp; + INIT_LIST_HEAD(&desc->entry); INIT_LIST_HEAD(&desc->pending); INIT_LIST_HEAD(&desc->active); desc->status = DMA_IN_PROGRESS; From patchwork Wed Dec 11 15:06:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 181233 Delivered-To: patch@linaro.org Received: by 2002:ac9:44c4:0:0:0:0:0 with SMTP id t4csp908051och; Wed, 11 Dec 2019 07:15:55 -0800 (PST) X-Google-Smtp-Source: APXvYqwH/CkK+KSF/rUPSlhBC6pv3y2q1WxCmP/UHmKzxUseEcUN6VP5Nj1s53fZd5uWm7Ep3JW7 X-Received: by 2002:aca:edd5:: with SMTP id l204mr3283252oih.98.1576077355727; Wed, 11 Dec 2019 07:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077355; cv=none; d=google.com; s=arc-20160816; b=eNImB8yQ5wxz5eXxDSi0AcUn6Il7hOQysfyBGre+nxOhF9l/rAzjJARLt58XYw84t8 m8mDaPC7oORSpvTNmc3xuVz/ZyV+mhtyN8m4Nu6i3HGLvzf1ztkLihzLeLRRMiXL2Naz 8LcEf4Lx9CDeiASBv6RlSCkyLjavKCrFFYlu8q4xpIgFOoDp0mloMl6m8Dh5OTuqfCJC 0/Q8dJPJX+LNGX+/MddmUwIT62AP+3NJ3Ij69wBn5H8GTgCyYagtWOYzoYIz/hY5kLzE W9oYcH0+qHOXPuPTn73ObWsLLJp493ThB7mflfB/shKvOWByR8bjW8nakrjeqGnTMAgP FfVA== 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=ZWt/Cs13Rs2/7EV+5e5/rbugaTGYl1TT/NK9jH4kh/Y=; b=G7tEDighGuGTYoGbJzukCyHB3eGHpQXk6NrJekV2W5q7/a1iAuXdoKqY8qZ6DG3GP+ M1H+jWw+O3CWsL4zN6g/mkZwKx6J3RnTDfehgHzF5G1HKb7MVn640QqByhWP0F8N4enq 0nZ+8rz5lMH8AQlURqZZ9pw8p1u/+LlhfKjC1HuQEO5QnSmH9Cxx85RKjSqYNCw5dlfP RkyHkbz9Xz6fJWDkPEQ/VaeuL+YSc85N70WYksgokliI6OdPb4F82R9A95GBCdEuZra2 yCwTl6utgDYEUE1/Ljpgfalh28vtaNoi1emSa5EPOKy/l2xjkit9aFbu5PQqNefOnKxd DZOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wSz8WYcQ; 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 t28si1275776otr.16.2019.12.11.07.15.55; Wed, 11 Dec 2019 07:15:55 -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; dkim=pass header.i=@kernel.org header.s=default header.b=wSz8WYcQ; 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 S1731308AbfLKPPy (ORCPT + 27 others); Wed, 11 Dec 2019 10:15:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:42250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731568AbfLKPPo (ORCPT ); Wed, 11 Dec 2019 10:15:44 -0500 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 E2E9824658; Wed, 11 Dec 2019 15:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077344; bh=wytKeplqK/AKhB4cIpXTYLqEbmNYTJ0B2BTWnB98EBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wSz8WYcQZc4wiaFJg5GP/j/ZC953qLA2fovNJFbHLckR6s1Vr15y4jScElseK3xnO PWi7kywf56whDVZn7RRFk1Z0zBy5a8kM+x3hO42rxN6nS8Ur7dqgfK25qBs8YzjEFB StXYNlc8KjrVUFRf0mD7WR5JkfXcVIfTnbF5FY20= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Herbert Xu Subject: [PATCH 5.3 090/105] crypto: ecdh - fix big endian bug in ECC library Date: Wed, 11 Dec 2019 16:06:19 +0100 Message-Id: <20191211150300.743726216@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit f398243e9fd6a3a059c1ea7b380c40628dbf0c61 upstream. The elliptic curve arithmetic library used by the EC-DH KPP implementation assumes big endian byte order, and unconditionally reverses the byte and word order of multi-limb quantities. On big endian systems, the byte reordering is not necessary, while the word ordering needs to be retained. So replace the __swab64() invocation with a call to be64_to_cpu() which should do the right thing for both little and big endian builds. Fixes: 3c4b23901a0c ("crypto: ecdh - Add ECDH software support") Cc: # v4.9+ Signed-off-by: Ard Biesheuvel Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- crypto/ecc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -1284,10 +1284,11 @@ EXPORT_SYMBOL(ecc_point_mult_shamir); static inline void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits) { + const __be64 *src = (__force __be64 *)in; int i; for (i = 0; i < ndigits; i++) - out[i] = __swab64(in[ndigits - 1 - i]); + out[i] = be64_to_cpu(src[ndigits - 1 - i]); } static int __ecc_is_key_valid(const struct ecc_curve *curve,