Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1753048lqs; Sun, 16 Jun 2024 03:10:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWV5PSg8WxAENtdqs9NrNcmd0pzBJDrf+kX29kvIMMQzpBXuoSaiYQSLSK0+jzLtWjTNQ0/OEIiy77bMXcR7iaXOcj2KXDKmZBpGBBoYA== X-Google-Smtp-Source: AGHT+IGMXe8VBZlbDcXuNVt4JtEZZrGVuWPPOKqRTKFXQge0xR5DiIeaHkUeA5inULUMuUTYY0eB X-Received: by 2002:a17:902:d4c1:b0:1f3:46fb:2ebd with SMTP id d9443c01a7336-1f8625d3fe6mr77732265ad.16.1718532620830; Sun, 16 Jun 2024 03:10:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718532620; cv=pass; d=google.com; s=arc-20160816; b=Dw8HwWipfpbfCFp1bGymkmOY5/6CDjLOIsVK2A4izp2ecgnIYBAXV3dL3QwlTE9hHB Qgc04PwuPsfEbXT0Drz+p8eOI6smyFpxWsgtbXhLKdhiIiIRzzTt1zPaNg/9aidTUW/E VG2YVWDbDpOi/EBnY6p/94yLLKBw1OJxTO+1hrXvtNrpn0PIfSVIu8PM0GxyO9n0RlLd 7ciCFObnY40RZQoKrF8lxqiq/2JfSkGybEGXkajphoGqYsiwy3YN9XPybtGPwWax1WZs 7MW/e2pJISTxjIytHQzryIf7158V6PMug5ZLmLzQz9krzq0/D2VkT5eGNiUPmScbgB1j 5dDw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=9xyXhAeo49aC8DKh9TZViKMhWhlQ4yFfeDwwGJY3Zxk=; fh=axVkXaZMnKTgpDwN/whe1KrhuBsuRyawOIMfDlUJNWA=; b=k8EyVyx8A3Fr+9Gkz4QBG2uHn9lhANv2ms84ZQyFEE7CQFzO0vvN1f9NAQSDcyS3+G avX3J92SfQRA4qvmXz4Q6sJ7OgqUPR/aG3/wAcTYguoWOGExFOQGwc7mIgGYC7X42C4l iA3WKntDc1wG/S+Xjn4fzysEL1wjxUQcwbyHmBuyMwQ69wSQ17QKLHD6uSksWvmR1Rrn B0kmoy6sgrcGifWYbqsrZhPVUD3j6GWF205wOOF913cx+VSHD3LjTJy/iZFFIqm8HMuy FLgC/62wzSnDUjF4pw1d+SV2omiKthYdniqchgI/PT6ZUkf0/oX2EKUePgMc8GzgHPEK u3KA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qg+gW+KM; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-216230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216230-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f855ee1c87si72788745ad.337.2024.06.16.03.10.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jun 2024 03:10:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-216230-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; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qg+gW+KM; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-216230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216230-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.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 74EDB2813ED for ; Sun, 16 Jun 2024 10:10:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E67C186E3F; Sun, 16 Jun 2024 10:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Qg+gW+KM" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 34ABAC152 for ; Sun, 16 Jun 2024 10:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718532613; cv=none; b=O5cMQQBl9nn10WN3w3LB7xqhdsER71tuX0Jmc9IbahV4wyUa0kjVqok8RCEsD3AFHNuitTgmlt1c8ikrFuJnqvECLjh6I3QLczLRljrQJ14OXoWd+3tlfZyAWDat+p8+TRQDTGblaREt/DN311cJiJEoC68sPlbfEm8sapMzcuw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718532613; c=relaxed/simple; bh=lOBdN9gfq3G/vMpx6VKqrb7Hwexc2IOn4skIsdgP8/M=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=U5gw2GVMD3dXpN5hxmdca+AVhqc93+ry41UZNneNhnjZhHEtOiJdBFe80ul2nOMeS6fZufiNgCJY8V0eFYbKSRNWzOHcHmDCZsmNA/lTl9Yu2E7wpKlq+Xcg0l5R8gn+fkFJKcKWIsAFmSeq6gT7ELghtjOBuoRdYb4DjqwG3mM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Qg+gW+KM; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45GA05M2028996; Sun, 16 Jun 2024 10:10:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 9xyXhAeo49aC8DKh9TZViKMhWhlQ4yFfeDwwGJY3Zxk=; b=Qg+gW+KMLQUClqGJ EDgRTJ1nYdu/OTi1dngQ60Ui8egIY+d9DrS6g5CT8plG009YP5SZYDkeyDuzcTpU ZtkJuyQEZnPkPhMF2TWx/LGgUgERDUHyG5xYm17Gtqgup+1Iiq1DdnsFm6vadUds pdtQyRmV83lFSIoZ3HLfVm9qRaJQlRm5qVjFWdHx5mEoIHQxPGV8Hwp+nZY8HmQe ZQd1Rearb4Lyc07BNWsgOjUNVfdqdjXWzi+LQKM4GXBcl7D+ygUh2PdkxzcEOa2n 1VYAXQ5FVX+phUxR7Wclld72SYYd0M3FSo35LgLSoIjoI+p3iWNUm12WddbzBm4P Fk5E0w== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ysv5xg3ap-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jun 2024 10:10:06 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA04.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 45GAA5d2005363 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 16 Jun 2024 10:10:05 GMT Received: from [10.253.10.202] (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Sun, 16 Jun 2024 03:10:04 -0700 Message-ID: <4f691c9c-8882-4bd7-ba60-3fc665d0808c@quicinc.com> Date: Sun, 16 Jun 2024 18:10:02 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] devres: Fix devm_krealloc() allocating memory with wrong size To: Greg KH CC: , , , References: <1718531655-29761-1-git-send-email-quic_zijuhu@quicinc.com> <2024061609-breezy-magnitude-8edf@gregkh> Content-Language: en-US From: quic_zijuhu In-Reply-To: <2024061609-breezy-magnitude-8edf@gregkh> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: tiO1Hdo_mN6EhTFz0u8xRjudG0qHALni X-Proofpoint-ORIG-GUID: tiO1Hdo_mN6EhTFz0u8xRjudG0qHALni X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-16_08,2024-06-14_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=914 suspectscore=0 adultscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406160079 On 6/16/2024 6:02 PM, Greg KH wrote: > On Sun, Jun 16, 2024 at 05:54:15PM +0800, Zijun Hu wrote: >> Kernel API devm_krealloc() calls alloc_dr() with wrong argument >> @total_new_size, and it will cause more memory to be allocated >> than required, fixed by using @new_size as alloc_dr()'s argument. >> >> Fixes: f82485722e5d ("devres: provide devm_krealloc()") >> Signed-off-by: Zijun Hu >> --- >> drivers/base/devres.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/base/devres.c b/drivers/base/devres.c >> index 3df0025d12aa..1cf87ddf1f55 100644 >> --- a/drivers/base/devres.c >> +++ b/drivers/base/devres.c >> @@ -898,7 +898,7 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp) >> * taking the lock as most probably the caller uses GFP_KERNEL. >> */ >> new_dr = alloc_dr(devm_kmalloc_release, >> - total_new_size, gfp, dev_to_node(dev)); >> + new_size, gfp, dev_to_node(dev)); > > Wait, are you sure? Did you properly test this? What is the actual > savings and how do you handle the fact that you are now not allocating > the space reserved for the devres structure itself? > sure even if i did not test it. beware that alloc_dr() will call check_dr_size() to reserve space for devres structure. it will reserve the devres structure two times if using wrong @total_new_size. it is obvious wrong. > thanks, > > greg k-h