Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1286426lqb; Thu, 30 May 2024 06:15:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXnenbQmWlQNsU3/uMDjA3PEOF84cdIHCz3WVABSbXEITb/59pLCKdDaMChhEsjYDYZFhEdQ6QLyloAHZYr7BFvM8lUxUW2rb6tFIp6zA== X-Google-Smtp-Source: AGHT+IH3+i9z4k4pEJAe/Gt/3re9SgUFBaJXUAi52A2PlM5JG8SiimIpPqT3XRbVk2J7SA1T3hKW X-Received: by 2002:a17:902:f685:b0:1f4:5b00:3fa with SMTP id d9443c01a7336-1f61a4dadd2mr25273215ad.58.1717074903335; Thu, 30 May 2024 06:15:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717074903; cv=pass; d=google.com; s=arc-20160816; b=V31QE1Hcf7PKTuCoW6VPgBog/RE1Fr19WFOjuJyiow9SnHMt9ovcxuEPoFHEfqMMnl rkmCsARCHg4qp/TQYvtkrpQ7zzfvxo8Df3fXCBnMNVzurDVyuPk0w0ve4pnQrg/1t+g8 +F7dOvlhdR9VLGKcUnJ74+Sbfm75LdnBD0LUpg644NhFaLyk4FS9AbzoxU/UKhUny8IB LJCMF8QKEAD60La9ubgk2Fkh5C9Wy9ZupNcDxM6i4R2Pbve74t33GTSYb4+378Iryex8 +0p2Vuqnew2Ad1prN6z2Jx02U1Ip4MjLEBWDW9AY7/lC6Gqb71mD18VWhKG2et5u71r+ A5nA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=CI7qvyTWDaOQHoF82DiW1sRaLov/b98yD46SoneeTkw=; fh=2wlAcivui/scOA93tZXEZLLsxRQFrv9BGWcT2Pg63XE=; b=wRHvpoGUveJtf1/BwjVQ40tV8RxX33roioBpQV8O9zdlPhj8ik2ZAlNIPhnD7eLgMl rmWTGMhLzFdZ3EuzL21KoYd/4WeDjdhWNSkGtk9SYnvBUc9QzA330bULt+EMs8Ntykpt KFT55U2gK4xXlcnNFV3GKzBWWWCuTyh+OXr6X3HlfWZeVu6WjLUfNqRR9UNZwsL4CKBk zm2zZrwANlGG+FS3iGHKNB75H/cjEW26TPl7fHdd494S8LHKSVuCMhO7kpnGZk6Ly/DA M55he9CCwV4ywGN3yPR9tx8LxLA54V6Lug4Ecrex94hMeYqDfB/l0TSahYNrEwSlH14E iDfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=IZdFQ5oI; 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-195407-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195407-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-1f44c78802csi120914985ad.96.2024.05.30.06.15.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 06:15:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195407-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=IZdFQ5oI; 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-195407-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195407-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 EF963284345 for ; Thu, 30 May 2024 13:15:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 838A0183075; Thu, 30 May 2024 13:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="IZdFQ5oI" 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 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 Content-Type: text/plain 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 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 delivered over netlink") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu --- 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.com/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 *env) len = strlen(env->envp[i]) + 1; if (i != 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])); for (j = i; j < env->envp_idx - 1; j++) env->envp[j] = env->envp[j + 1] - len; -- 2.7.4