Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp336098lqb; Thu, 23 May 2024 22:35:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVKVdB3HGseCc083Of4mFoV+X8rynXIDhtERkhUHcm86b0H5QJoMfXSp4uTKTD3J/MelAhxwJrUcis0CXDwG9hbbHabqEQixZZuLK+OGw== X-Google-Smtp-Source: AGHT+IGLOhW8TwD37K5hRVAp1YkBTd1AfiCaKfuV7zCj9lnvjLDL4Feoeo+zwlde9sLurlR86+cl X-Received: by 2002:a17:906:7d86:b0:a5a:891b:416b with SMTP id a640c23a62f3a-a62642d8719mr72589066b.20.1716528911037; Thu, 23 May 2024 22:35:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716528911; cv=pass; d=google.com; s=arc-20160816; b=dmwnaFzqhGFBUDq+15JvyRtcUV25gdJZZ9c0IltzpFzooWtfiMvH5xuQWSz1e7k0kc 9LX0Iu+rNzsk3xLMWZXKX5HZfeEkRj+z+0gjE3y3zIaEIjwTFZ3ux7w+/cLOwu196UUm 8qqz4hJvT+nb4+ZRm9+sCtBEBb0edNFATnC+InDqYoLKHqmsAZKQYyk4DqUF4wuzplF/ D9e4QdqC79rMe/EsOYFiUl2aChkMqrTeNGb+YYcPCCvzcD11bPgRZ0sKrH0XfOVAeBYo 8ZJ+8Y5w6j/RSNOGQos2FoYNcGXMi01pafXXMmtFCxgxCd0/htgJnvn3ZmY8KqgGPgvY s/6w== 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=ypuoMEpVS3J8z1ZDzYni9eiy/aWKMP2ljn6gXcXq4Jw=; fh=aIjkPo5W9BVPwL+IRYNPLl5XCFSb4MTXvF9p/Z70fhg=; b=cU79kxv66cVyOeTo1Fd9bvIo/rUsaiuXmENFmid6b+G3WR8wZe99GevcttOHrK9EhA 0sAM6uaXbP40GMg6UY9q9uJaVvAsN6YujZ0+JsZAJetsf5ZTX6NDt5QK6+4PRVGPp/ZD rumoyxM0+bjR4uv0mDtPNo9mMyxgYZbFrIEU72hmIbgC/JexchI1Z0XIEvP/CVsNvwQk pAgS0REgeWBzhTE/KZN/ij8Up4V7jgj3EA2YzmCN1VbiL/Rd0Os7LKWld1HcQViooPtf Ad3CmvFALlNEZjW2fAQbSuu2CSzReovOMQSFQbzpwemz+RCQTg1wLuKxvWAsB2VkeHV8 hjWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RhHZpzAS; 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-188334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188334-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cc38139si42487566b.428.2024.05.23.22.35.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 22:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-188334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RhHZpzAS; 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-188334-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-188334-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B18781F2222E for ; Fri, 24 May 2024 05:35:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08DA97E792; Fri, 24 May 2024 05:35:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="RhHZpzAS" 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 403B01CFB2; Fri, 24 May 2024 05:34:59 +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=1716528902; cv=none; b=g6HuH4n5s4YFpxR5VCc0AxK6CmroHg+y1Sqi3yUAZB1IUoYCevdGRmMPVwXYHPzOhQJmayZkz7PeWsK+btiW0Tm9wuCjJatjEqtmzJ1yAw0IWFAXMDcG6E7WdlTab3uWvtlEQziLFgc6wA3gPWSvuhgrjcpqLnOK97gf5OLEsM8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716528902; c=relaxed/simple; bh=FlDGgVlQguOnjV6UYWXfJd/mNTXYd9Qlgc99324n+Bs=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=Whg5CuZumEwVavxFc3/m77zgHPDWrWYjuTgF90MZAZHwFQxO7gRZFVvXDPwDv+LtW1R3ZoH2lc30LYwOrRuG10D+F21T2iDt75EbP8Z1S5tqeGnZ49Zv13UdvjI6VaNE0M/OUKwcbh68FiY3GEdaJ1echAT1UXG2IaaOPqIF6j4= 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=RhHZpzAS; 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 (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44NNOv8i030714; Fri, 24 May 2024 05:34:53 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= ypuoMEpVS3J8z1ZDzYni9eiy/aWKMP2ljn6gXcXq4Jw=; b=RhHZpzASb83cnO0Y NfoHa9js2X+DrFEgyWW5/BaSyISgxP0qncUC8VDMCGsEpfwHxlvY8tax8WcHg0kp Fyav+GVSTozPXAFVCvNg5ZSZY3yVoH7JhQnW/e1PRELVjjxZL5EQ1H+k9uyBuD39 cYYMsD548yLXXwmy/sCvs+K9mRhYzuprVhSqixxh2jJhpCyoEiFlCtD6pD5oCKIA FYd2msQJwy7WtzxI6VOV0tcHflUTT+fOnzRp3+Xn/954WVT0qaCpFZDkOMnQ79+V W3jYPAx6TwwDZEUqofPthkXWBcZXEOEW81zkI7tY3E3iqUs08631dPlB8iAETlb+ Q9dM1g== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yaa8j1a21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 May 2024 05:34:53 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 44O5YqLQ002092 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 24 May 2024 05:34:52 GMT Received: from [10.253.37.124] (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, 23 May 2024 22:34:51 -0700 Message-ID: <5acce173-0224-4a05-ae88-3eb1833fcb39@quicinc.com> Date: Fri, 24 May 2024 13:34:49 +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] kobject_uevent: Fix OOB access within zap_modalias_env() To: Greg KH CC: , , , , References: <1716524403-5415-1-git-send-email-quic_zijuhu@quicinc.com> <2024052418-casket-partition-c143@gregkh> <74465bf5-ca18-45f8-a881-e95561c59a02@quicinc.com> <2024052438-hesitate-chevron-dbd7@gregkh> Content-Language: en-US From: quic_zijuhu In-Reply-To: <2024052438-hesitate-chevron-dbd7@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-ORIG-GUID: QQxQupERDckqvqp6h21MhJMjAqxP4dYy X-Proofpoint-GUID: QQxQupERDckqvqp6h21MhJMjAqxP4dYy 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-23_15,2024-05-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2405240037 On 5/24/2024 1:21 PM, Greg KH wrote: > On Fri, May 24, 2024 at 01:15:01PM +0800, quic_zijuhu wrote: >> On 5/24/2024 12:33 PM, Greg KH wrote: >>> On Fri, May 24, 2024 at 12:20:03PM +0800, Zijun Hu wrote: >>>> zap_modalias_env() wrongly calculates size of memory block >>>> to move, so maybe cause OOB memory access issue, fixed by >>>> correcting size to memmove. >>> >>> "maybe" or "does"? That's a big difference :) >>> >> i found this issue by reading code instead of really meeting this issue. >> this issue should be prone to happen if there are more than 1 other >> environment vars. > > But does it? Given that we have loads of memory checkers, and I haven't > ever seen any report of any overrun, it would be nice to be sure. > yes. if @env includes env vairable MODALIAS and more than one other env vairables. then (env->buflen - len) must be greater that actual size of "target block" shown previously, so the OOB issue must happen. >> do you have suggestion about term to use? > > Some confirmation that this really is the case would be nice :) > >>>> Fixes: 9b3fa47d4a76 ("kobject: fix suppressing modalias in uevents delivered over netlink") >>>> Cc: stable@vger.kernel.org >>>> Signed-off-by: Zijun Hu >>>> --- >>>> lib/kobject_uevent.c | 2 +- >>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>> >>>> diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c >>>> index 03b427e2707e..f153b4f9d4d9 100644 >>>> --- a/lib/kobject_uevent.c >>>> +++ b/lib/kobject_uevent.c >>>> @@ -434,7 +434,7 @@ static void zap_modalias_env(struct kobj_uevent_env *env) >>>> >>>> if (i != env->envp_idx - 1) { >>>> memmove(env->envp[i], env->envp[i + 1], >>>> - env->buflen - len); >>>> + env->buf + env->buflen - env->envp[i + 1]); >>> >>> How is this "more correct"? Please explain it better, this logic is not >>> obvious at all. >>> >> env->envp[] contains pointers to env->buf[] with length env->buflen, >> we want to delete environment variable pointed by env->envp[i] with >> length @len as shown below. >> >> env->buf[] |-> target block <-| >> 0-----------------------------------------env->buflen >> ^ ^ >> | -> @len <- | >> env->envp[i] env->envp[i+1] >> >> so move "target block" forward by @len, so size of target block is >> env->buf + env->buflen - env->envp[i+1] instead of env->buflen >> -len. >> >> do you suggest add inline comments to explain it ? > > Yes please. > > thanks, > > greg k-h