Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5734580rdb; Wed, 13 Dec 2023 19:08:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpZKDM2+i+pRiuuQ3aIVVBdRB753ZXgqREuSpkOaQLOsvXZyp6ajPBW2HbGbfBT59kgd// X-Received: by 2002:a05:6a00:6c9e:b0:6d2:31df:5eae with SMTP id jc30-20020a056a006c9e00b006d231df5eaemr446438pfb.55.1702523326199; Wed, 13 Dec 2023 19:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702523326; cv=none; d=google.com; s=arc-20160816; b=CH8e2d1MgIDov7qDB92bmlb60cq1/AFbk08lZulsxp1HpkU2PZ1r+l7DWPoasCa5wR 8oKTW8cG6Uyj4191K0KBWiytIcXE+sZ6c0KuhdllyvpTjapmi4fyZgazcPUpfpyXyF+7 bQZLtRuPq1CbNCa2HRRbrSj2HGogCMvzwRGS8AYjK82zydfjZfL0Ol9qx7FonQG+elyT 4V4BgK5Vy47du+HYN6VYYfahrV1TLXTkD1fZbZZHNP7GdfpUSZMyuu/EyQxF3Yimfs5t Xt0gc4aqJrFr4vNioOKDIcYkA80d+Ua1rqIQFGuuXThpBtfdD91WInE7vH0PceWdzQx0 +iHA== ARC-Message-Signature: i=1; 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=6eA1O30RGkm4+e0jHK53dR7i+TD0qTNRQc7drrhGtwo=; fh=/TS/mHffID6mRuPMVSBxRtbxR/d15Bs0u95gmaNOlzE=; b=fr6/BqfSU5S2HEZxC9GF1uICR+k7hWcak6cc7RdKU/2TZfK5QQOZf1VH1x/4S06q9u Q98SzYCfgMMIDRvFgKI8HZJKxNcnAJDGBbgdlj5oSQPd379HH0Y7/GH9I1oEGeoZ3tA4 sgm/5nl8YeQTkBecTx8e8y40aN5j4lMyabnRzAYOKLFV+m68JI7hIqnjipC+8H87r871 4b9kRfXuPyWjRfYZpMLiUK6odDXVWsj+UEBnGALFh6yK6qdWHAcIMdkqqAcGnXUrPi2q U9JVKzo8JL8eMWRhkN8762fw1WQVoMXZ7WzlXNQxUQozGIww39KpQbcyTbvkdZOHpjja ZoxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto+bounces-823-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 23-20020aa79117000000b006cdaa195ea6si10479966pfh.69.2023.12.13.19.08.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 19:08:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-823-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto+bounces-823-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-crypto+bounces-823-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DC407282A89 for ; Thu, 14 Dec 2023 03:08:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 878DD1375; Thu, 14 Dec 2023 03:08:42 +0000 (UTC) X-Original-To: linux-crypto@vger.kernel.org Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6253D0; Wed, 13 Dec 2023 19:08:37 -0800 (PST) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VySjsdn_1702523314; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0VySjsdn_1702523314) by smtp.aliyun-inc.com; Thu, 14 Dec 2023 11:08:35 +0800 From: Tianjia Zhang To: Herbert Xu , "David S. Miller" , Mimi Zohar , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Tianjia Zhang Subject: [PATCH] crypto: lib/mpi - Fix unexpected pointer access Date: Thu, 14 Dec 2023 11:08:34 +0800 Message-Id: <20231214030834.2665-1-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When the mpi_ec_ctx structure is initialized, some fields are not cleared, causing a crash when referencing the field when the structure was released. Initially, this issue was ignored because memory for mpi_ec_ctx is allocated with the __GFP_ZERO flag. For example, this error will be triggered when calculating the Za value for SM2 separately. Fixes: d58bb7e55a8a ("lib/mpi: Introduce ec implementation to MPI library") Cc: stable@vger.kernel.org # v6.5 Signed-off-by: Tianjia Zhang --- lib/crypto/mpi/ec.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/crypto/mpi/ec.c b/lib/crypto/mpi/ec.c index 40f5908e57a4..e16dca1e23d5 100644 --- a/lib/crypto/mpi/ec.c +++ b/lib/crypto/mpi/ec.c @@ -584,6 +584,9 @@ void mpi_ec_init(struct mpi_ec_ctx *ctx, enum gcry_mpi_ec_models model, ctx->a = mpi_copy(a); ctx->b = mpi_copy(b); + ctx->d = NULL; + ctx->t.two_inv_p = NULL; + ctx->t.p_barrett = use_barrett > 0 ? mpi_barrett_init(ctx->p, 0) : NULL; mpi_ec_get_reset(ctx); -- 2.24.3 (Apple Git-128)