Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp385315lqi; Wed, 6 Mar 2024 23:14:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV5ciX+SmvlcSvBuA2ArGGx95MwLKIS81F19id2GYe4XPhr+fC0eeqJ3PrRhu0GMB8tqgBG00CZ5a63JYDWaKIljLTHCxAVAsBnGysbFg== X-Google-Smtp-Source: AGHT+IF4ffneXJgHm3eRWrYZ1fABymWEOKcgDnyLaWQuhQLRhPYRZlzpG42Ee1fmRTHVarHnJ3HN X-Received: by 2002:a05:622a:cc:b0:42e:d10c:fca6 with SMTP id p12-20020a05622a00cc00b0042ed10cfca6mr8794788qtw.2.1709795660905; Wed, 06 Mar 2024 23:14:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709795660; cv=pass; d=google.com; s=arc-20160816; b=FMSeEK7KIOlXNmCgu89/pgxR0UiVVvseIMCu7GbGVfOepI3AV3/x98kcK4Sui8If1f jyFMtenbDrmxzCSSm74E3ByveT11Prx2cykssuPq/q0cbDeQEpLbJnplUClDk6Zqr0jQ 0VxG81br+S4TMsTr3K/15QodvUjz1miJlaDXQ68KM7hc4V4Ai5HXmMfh0Kh7MzMvUZfT fkSTPuUrGQmwAmnZaR4+QHQt9w7mNj8ScXICKjEOLLly8Nru50VnHA53XotUa6FSodjM uvRVYYoBCfrnItIuluoD0mC6vsknYtPDA87tMQ6wCnLS4iSMbF7VQLdoaePJ2ebyjhVc rKZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=qSd3tRlCOt2VoTc5Uel992Zz6Kt2V5uMh9SIFk8uSrw=; fh=SiYzAReLSBraNc1vGWWJIagyXPi6YtmVMXlY0hxHgxo=; b=ZKVRmjQ731Wa6JMWt7JPawPaEwcv50QabWU/LLUhZBn7JOph8zQa2PoS0XbyBl2Bg5 0q86PS7dkB9Bk+3xgXi8EGDMf1K6y0m1I6uPqMdbd94EGu/aZrFh6iXvhHDrQYCUi/YQ 3q1dNUsB7qZ3ZiTmXiCvRHUS56dzK6IUzLCJ//gi/5ELx+jva6x9ME3JE3vyJCtwlFfw DNCz+ua+Cze/m6hrHbHu+lBvC9HGkRPQoDM9A8+xNr7Rfwqel0R5e9A9G3TPoSIwDOn8 6VUE7YwnoEHsa3ItTGoj9o+nGL+SfNdjR7VkSeWdgQTKJ5F90ap27ZMqbfjGT/kIkvWb +F+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-95042-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95042-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z12-20020a05620a08cc00b007882ed51df5si6899727qkz.177.2024.03.06.23.14.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 23:14:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95042-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-95042-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95042-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 98BA81C20C98 for ; Thu, 7 Mar 2024 07:14:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10FB71CFB6; Thu, 7 Mar 2024 07:14:13 +0000 (UTC) Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2744D1F932; Thu, 7 Mar 2024 07:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.154.21.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709795652; cv=none; b=A9eczeKoM/jllG9MVuQaCHVdhyX1JPZOmmztTeqPGxLV7uIOggIY5WMKVGuniYflKe5QJjR2MRtJ60b0YhyuRaG83KtdIokIW5ImsRJQdlk7F/CERet0/Qbig/pjpYr1JP6b9RpCfXYF5y/SWID5WFrj6pc3J5czw6Bkvzwb1UA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709795652; c=relaxed/simple; bh=I0Eb1RcvG2mnFN9txzANi9+x7+5ju+ursRojhbBWMVQ=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZuDu4Q0K9KtLjR9OfBGnXBcPC7oHr+E6r/a/HEBjmg6cYbJgxTeon5nwY3ZHZo9cwD3fnRZJs0XvsNI66rusrbX/1S/G0sFloqZPL+1ho9ICqAZTE5yLImJd1O48Qml2Dt/ckAuKXhzwcA/E227ZvyOrut5I/Wz4J3DE70mTlxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru; spf=pass smtp.mailfrom=omp.ru; arc=none smtp.client-ip=90.154.21.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=omp.ru Received: from localhost.localdomain (78.37.41.175) by msexch01.omp.ru (10.188.4.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1258.12; Thu, 7 Mar 2024 10:13:56 +0300 From: Roman Smirnov To: Herbert Xu , "David S. Miller" CC: Roman Smirnov , Sergey Shtylyov , Karina Yankevich , , , Subject: [PATCH] crypto: ecc: fix NULL pointer dereferencing in ecc_gen_privkey() Date: Thu, 7 Mar 2024 10:13:18 +0300 Message-ID: <20240307071318.5206-1-r.smirnov@omp.ru> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: msexch01.omp.ru (10.188.4.12) To msexch01.omp.ru (10.188.4.12) X-KSE-ServerInfo: msexch01.omp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.1.0, Database issued on: 03/07/2024 06:56:30 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 59 X-KSE-AntiSpam-Info: Lua profiles 184019 [Mar 07 2024] X-KSE-AntiSpam-Info: Version: 6.1.0.3 X-KSE-AntiSpam-Info: Envelope from: r.smirnov@omp.ru X-KSE-AntiSpam-Info: LuaCore: 9 0.3.9 e923e63e431b6489f12901471775b2d1b59df0ba X-KSE-AntiSpam-Info: {rep_avail} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: {relay has no DNS name} X-KSE-AntiSpam-Info: {SMTP from is not routable} X-KSE-AntiSpam-Info: d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;omp.ru:7.1.1;78.37.41.175:7.4.1,7.7.3;127.0.0.199:7.1.2 X-KSE-AntiSpam-Info: {cloud_iprep_silent} X-KSE-AntiSpam-Info: ApMailHostAddress: 78.37.41.175 X-KSE-AntiSpam-Info: {DNS response errors} X-KSE-AntiSpam-Info: Rate: 59 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dmarc=temperror header.from=omp.ru;spf=temperror smtp.mailfrom=omp.ru;dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 03/07/2024 07:02:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 3/7/2024 2:51:00 AM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit ecc_get_curve() can return NULL. It is necessary to check for NULL before dereferencing. Found by Linux Verification Center (linuxtesting.org) with Svace. Signed-off-by: Roman Smirnov Reviewed-by: Sergey Shtylyov --- crypto/ecc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crypto/ecc.c b/crypto/ecc.c index f53fb4d6af99..fd63e354895b 100644 --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -1471,9 +1471,14 @@ int ecc_gen_privkey(unsigned int curve_id, unsigned int ndigits, u64 *privkey) const struct ecc_curve *curve = ecc_get_curve(curve_id); u64 priv[ECC_MAX_DIGITS]; unsigned int nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT; - unsigned int nbits = vli_num_bits(curve->n, ndigits); + unsigned int nbits; int err; + if (!curve) + return -EINVAL; + + nbits = vli_num_bits(curve->n, ndigits); + /* Check that N is included in Table 1 of FIPS 186-4, section 6.1.1 */ if (nbits < 160 || ndigits > ARRAY_SIZE(priv)) return -EINVAL; -- 2.34.1