Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp215331rdb; Mon, 22 Jan 2024 18:15:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFNG9oy7lk+gf1ME+b8V4n3otmtt7I+JTL1meIe/yza2IogeNoy7Jy4c414Jhpq7v1usjU1 X-Received: by 2002:a05:6a20:d81b:b0:19c:24ae:d930 with SMTP id iv27-20020a056a20d81b00b0019c24aed930mr4176596pzb.58.1705976138957; Mon, 22 Jan 2024 18:15:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705976138; cv=pass; d=google.com; s=arc-20160816; b=a8+q3GUv/ZsZ5rNt1697/RwUxDYIdvk0h2Sgd6vhEK3sbL78acJOreB4UYaew5kN5l 20xOfKKXq8omeNPqw5yPvoNd56dTvBS9u/beC3vDsnQ9/uUh6G2Pzm433vPQ5k2Nmf5V nEh1KsFndK1o3I+TNhC/RWsx8ICw8jUNEfTLatA8nixNvBKuIQgwgC7d2jRgR9yM53dK wxCXsLTA3hA7Vo1wHovAFdp8mk4kHuIZZN8I7fTa9JQuUysH67XkIfr8p9KG8HH1YQoT 9aMFpKF3NJAseAwph9aYUpp13piEs1776W1LVwDFSU1l4kT2ig9Y7FKRndyxWwIL4lGU MQSQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34575-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w19-20020a63fb53000000b005cf60fdf283si9157472pgj.701.2024.01.22.18.15.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 18:15:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34575-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34575-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D4AD528BD21 for ; Tue, 23 Jan 2024 02:10:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8995D442D; Tue, 23 Jan 2024 01:12:04 +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=20J=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 Content-Transfer-Encoding: 8bit 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 --- 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; -- 2.34.1