From patchwork Tue Jan 23 01:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Liu X-Patchwork-Id: 190678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp77459dyi; Mon, 22 Jan 2024 18:15:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHq+AYBBzTSx/QUAS/mdEVHA3nlK+pmZDNB/1yuyf7yRKjOLGwqZsrR0rE89Htwb0XdpQXt X-Received: by 2002:a05:6a20:158e:b0:19a:ecc2:f308 with SMTP id h14-20020a056a20158e00b0019aecc2f308mr7663855pzj.35.1705976145304; Mon, 22 Jan 2024 18:15:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705976145; cv=pass; d=google.com; s=arc-20160816; b=XeByaoFHXOj4D/qwJMoBIb29tOL+msv1G9MgcanTWzm/uGvqR79nvHtr1u43Umsa2a 4asHuTHexRIrT6CbwxV2xYw3YmILPaa6j5wVDXQtXweeVC1RqKSE6YzjzDfpxkf+wFlt mFbiLoyZpbZ/bEp667xRO+meZV0naWTVWGOu16SxhuH3iFdCnidWKcN27qAh/T2+XBen reFmDlhKP0Ro8Ns/yneCgb33EZit0eLJgsmNBDTLlWzSSA3txtMbN7jOXQn5YWf9iqnx CkYsx09f8+oZGARw7aG/MR4ALqtRlJuAAnDf6cYkGG1dYX7zutEltcmWfj7gaRSvk1r8 A5zA== 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=pR+Gl6WZntdP8Z8iIm5ZazB34/6a9/oCgpL5ONQMweY=; fh=qkXoGPE99H4vu0R6JhZcaTp3geGrM7Zi07RNuzBI/q8=; b=xDHqIocZ20wZtyYmjWtkcHwCyfLNUr35g6ZecedAV9rAOUPo1lnzWJydg5g1kdXedw m8+QdkckeO6/8nyku197yDkLoJCk4azLZVzIPrBEcGE9ToAfXRELeNKxtIqjWoaCJygu jUYgYJ3jpD4B42m3YEIzCJ7PmojkDlLv5mMIwDB3QiwYmoe0zDJQkRmg/vxGKqxopAjX ROMTh6+PuN5zZ9VNWRbYT1igr+lM5U/lD3Fex5+tUmbTvHifqX3DdMI4pUIRD1xgP6Lj Qb5Kl+KfJqepH7LxdQpUK7C3llbQdVct7IsdIx//jClapVGQBFYbxAGs+ZQaK9gOZ0G8 kLKw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-34575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34575-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u8-20020a631408000000b005ce04177acbsi8849748pgl.399.2024.01.22.18.15.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 18:15:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=kylinos.cn); spf=pass (google.com: domain of linux-kernel+bounces-34575-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34575-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 099DE28C715 for ; Tue, 23 Jan 2024 02:10:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBEE223C6; Tue, 23 Jan 2024 01:12:05 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4437C3C3F; Tue, 23 Jan 2024 01:11:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705972323; cv=none; b=dt+HJ5gwF/tJm4JMogFEn+2Uglohiwr6wTwdg7GjcKMcXHQHD7XqF3d0AbufrC17wfh/0B76ammJyMcy+Ia3+JV6DGe4BV93EEMi1ew95ndpC3aSzUcjXgED2G1f1Elfs6GrVVunKwQglRp+SXLBBfeoHdRfWORGjkjjMdFLz8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705972323; c=relaxed/simple; bh=W/F9+FOnuXtpYbwfUt6UiEh6czwR/jZUdZbhJZ2b3ro=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=QcA66ieQPXT51sX0Alma4ghNU6dVRNIrptRyqCWffem7S2uUvo/fgNVNUbhVKN6EkjyhGz6lrh2mSqBoHMiMpAyO1Yc3FOoqW+KxbmGfYxd8IL7q7Obed9hC1dt6e33BcahRClUjghrpDlDNt7zViqpnIj0vc8Yya3eQMYDs4/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: cb7316e849fc4beb9305547c3302b2e7-20240123 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:dfb64aab-61b1-4851-9f5d-ad4ec6a2f7e9,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.35,REQID:dfb64aab-61b1-4851-9f5d-ad4ec6a2f7e9,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5d391d7,CLOUDID:92218a8e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:2401230911518DL3C44Z,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: cb7316e849fc4beb9305547c3302b2e7-20240123 X-User: liucong2@kylinos.cn Received: from localhost.localdomain [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA) with ESMTP id 257690614; Tue, 23 Jan 2024 09:11:49 +0800 From: Cong Liu To: Shyam Sundar S K , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Cc: Cong Liu , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] platform/x86/amd/pmf: Fix memory leak in amd_pmf_get_pb_data() Date: Tue, 23 Jan 2024 09:11:47 +0800 Message-Id: <20240123011147.6843-1-liucong2@kylinos.cn> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788845642319715281 X-GMAIL-MSGID: 1788845642319715281 amd_pmf_get_pb_data() will allocate memory for the policy buffer, but does not free it if copy_from_user() fails. This leads to a memory leak. Signed-off-by: Cong Liu Reviewed-by: Shyam Sundar S K --- drivers/platform/x86/amd/pmf/tee-if.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/amd/pmf/tee-if.c b/drivers/platform/x86/amd/pmf/tee-if.c index 502ce93d5cdd..f8c0177afb0d 100644 --- a/drivers/platform/x86/amd/pmf/tee-if.c +++ b/drivers/platform/x86/amd/pmf/tee-if.c @@ -298,8 +298,10 @@ static ssize_t amd_pmf_get_pb_data(struct file *filp, const char __user *buf, if (!new_policy_buf) return -ENOMEM; - if (copy_from_user(new_policy_buf, buf, length)) + if (copy_from_user(new_policy_buf, buf, length)) { + kfree(new_policy_buf); return -EFAULT; + } kfree(dev->policy_buf); dev->policy_buf = new_policy_buf;