From nobody Tue Dec 16 14:36:27 2025 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 471F817C9ED; Thu, 30 May 2024 13:14:55 +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=1717074896; cv=none; b=ONbUVYTErKNdtmJYw2ZuFXd18zGH+Ez6/5wkWkCanrcO5ZsDyTKOHXVH6U3Y+jAGKinBdCPSdehTpf8+Ea0SDChHOibRF63+VCk3+16f3D6K5lrnlpqGRJFprQdbRTzFsoDZNtZATO5ViiQI7X8Ha4SRiyV0ShpgrBEOb2LPwwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717074896; c=relaxed/simple; bh=6P+VwAaagp4NQy523Mobh1MaohV/v6UNe0PMtaDPfIc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=jvP/eb6OYvUkoTqb7HVV6baxMV5lBHZ/phItAQNxeDWYsiL7U0lMp+RPxnkliRwxpxXrbnKA+EIJieKrBJaoZslu31n2vh45jV+ztuCxJrSi4g4bRJPwdAbRUXnMKYwMf8BHR+pAyRWRUm1OUkgdHB9nYdueK/8LmOH7Gw+r2Hg= 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=IZdFQ5oI; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IZdFQ5oI" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44U5aOet015776; Thu, 30 May 2024 13:14:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:message-id:mime-version:subject:to; s= qcppdkim1; bh=CI7qvyTWDaOQHoF82DiW1sRaLov/b98yD46SoneeTkw=; b=IZ dFQ5oIS/mUDl5zLWkyICBpXw/xteQ3rGeCLDTruBbqfjDfojbBIYPAhXuMhbXUNG QmK9bK4FpX3HeQq8XnWNDZeHCA6utgiz3PC+ObFr7echyCtr7AbT739CgOqUlLD4 YKMz8BKO4sh4XqIzQ+TH5kMWtE+Sxy++2KkS7jnqtJnsP9wQ20eeB9zeOti5W6cw H4eoTyCsTgRtEzCvsW8QuO0OGVFz63I/vkNAASWDLmDHwY2C6ITn7xhWktrewxNN zEUMXLsxvlz4ZUqki7SP3lNvExtlQxnsFPCaG8yjNRj8OoY7qVzFmMspndr+QLVB uDjJolAIY5oGEshNREpg== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ydyws3qtx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 13:14:46 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44UDEjL0015828 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 May 2024 13:14:45 GMT Received: from zijuhu-gv.qualcomm.com (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; Thu, 30 May 2024 06:14:43 -0700 From: Zijun Hu To: , , , CC: , , Zijun Hu Subject: [PATCH v3] kobject_uevent: Fix OOB access within zap_modalias_env() Date: Thu, 30 May 2024 21:14:37 +0800 Message-ID: <1717074877-11352-1-git-send-email-quic_zijuhu@quicinc.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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-ORIG-GUID: jfydUX1drW9NFTelWlcg-7YoDtd5zTv0 X-Proofpoint-GUID: jfydUX1drW9NFTelWlcg-7YoDtd5zTv0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.12.28.16 definitions=2024-05-30_09,2024-05-28_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 suspectscore=0 mlxscore=0 mlxlogscore=845 priorityscore=1501 spamscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405300100 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" zap_modalias_env() wrongly calculates size of memory block to move, so will cause OOB memory access issue if variable MODALIAS is not the last one within its @env parameter, fixed by correcting size to memmove. Fixes: 9b3fa47d4a76 ("kobject: fix suppressing modalias in uevents delivere= d over netlink") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu Reviewed-by: Lk Sii --- V3: Correct inline comments and take Dmitry's suggestion V2: Correct commit messages and add inline comments Previous discussion links: https://lore.kernel.org/lkml/ZlYo20ztfLWPyy5d@google.com/ https://lore.kernel.org/lkml/0b916393-eb39-4467-9c99-ac1bc9746512@quicinc.c= om/T/#m8d80165294640dbac72f5c48d14b7ca4f097b5c7 lib/kobject_uevent.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 03b427e2707e..b7f2fa08d9c8 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -433,8 +433,23 @@ static void zap_modalias_env(struct kobj_uevent_env *e= nv) len =3D strlen(env->envp[i]) + 1; =20 if (i !=3D env->envp_idx - 1) { + /* @env->envp[] contains pointers to @env->buf[] + * with @env->buflen chars, and we are removing + * variable MODALIAS here pointed by @env->envp[i] + * with length @len as shown below: + * + * 0 @env->buf[] @env->buflen + * --------------------------------------------- + * ^ ^ ^ ^ + * | |-> @len <-| target block | + * @env->envp[0] @env->envp[i] @env->envp[i + 1] + * + * so the "target block" indicated above is moved + * backward by @len, and its right size is + * @env->buflen - (@env->envp[i + 1] - @env->envp[0]). + */ memmove(env->envp[i], env->envp[i + 1], - env->buflen - len); + env->buflen - (env->envp[i + 1] - env->envp[0])); =20 for (j =3D i; j < env->envp_idx - 1; j++) env->envp[j] =3D env->envp[j + 1] - len; --=20 2.7.4