From nobody Mon Apr 6 09:33:05 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 1B8AC2EFD9B; Fri, 20 Mar 2026 05:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773985312; cv=none; b=ABVsWi9TyyYcuIYOb34wrns21leVyuO6ihKn70Ad4P6TDKslHfiJMQb8kHWqe4uRueAxDmNlHits1SMvrpwd62GMPSL32KznnhSFiMBJ967gsIGWcaIER0viRlLjHQeTTNTvyxQdB8H34Ti41OBLWsvpLhJehc6TPzfJKj92ZS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773985312; c=relaxed/simple; bh=3IAZC9RjujDWWizlWlb5fytLxzNcU5RznP5JQz9VVQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PXLxKIMiTMQxDMndjHEmAfxa2A43kzvssISR2MymADq5xfBqP9VNLxyKVKw2JueN+C5o9JDxeP2ur2hZAtD4VX/m7t0qEk+8YaNRMG7ni54WLKdN+rtKCOhPgK079WDtyBFuoqtjNpN/tIOxPlsyrfzEmfV8jKF28qdaxaRQ0Gs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ktkU0LYT; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ktkU0LYT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1773985311; x=1805521311; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3IAZC9RjujDWWizlWlb5fytLxzNcU5RznP5JQz9VVQU=; b=ktkU0LYTFox+jpGCojK2ggk8MzcYHFvONzxCIEkrq5Rsy2x+JsUpTrv4 i9k48EATURpyGVblZp9B05nQTMb1/2IAKvdfIOTCNYNstDBGAIUxKyMx9 ptMXdYIi5IbIjdVF0CtYXS1uZG6JPdxvFlmvmomG05obscEHKcutD5+oG ptJHcDC4ytiwYCErxe7VvYYrSewo7BNfTZHUn/CG3SLmMWYjwUrLdd3cz Cuk5Z/nfysauu7pPSvo2lM8WbctihOujHYYQQXrWkM+xPmS+MasP3zUQT cm+ZCsDOvU739FCfnibnDPY6nk0zxvsErUuw+jX/AW/bQuyUjed7qm/Lb g==; X-CSE-ConnectionGUID: v2JR1RFxTM2OMaqIXSVmRA== X-CSE-MsgGUID: Qv2P+jA0RWSkVAX5JP7qZg== X-IronPort-AV: E=McAfee;i="6800,10657,11734"; a="62629458" X-IronPort-AV: E=Sophos;i="6.23,130,1770624000"; d="scan'208";a="62629458" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2026 22:41:51 -0700 X-CSE-ConnectionGUID: nkVdoFzmQIC/w5XpA7oOAg== X-CSE-MsgGUID: I8yN47diR8+nGKpaYeoO2g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,130,1770624000"; d="scan'208";a="223404412" Received: from emr-371.sh.intel.com ([10.67.116.154]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2026 22:41:48 -0700 From: "Baoli.Zhang" To: vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, perex@perex.cz, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Baoli.Zhang" , Andy Shevchenko Subject: [PATCH v1 1/3] soundwire: fix bug in sdw_add_element_group_count found by syzkaller Date: Fri, 20 Mar 2026 13:33:22 +0800 Message-ID: <20260320053324.738100-2-baoli.zhang@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260320053324.738100-1-baoli.zhang@linux.intel.com> References: <20260320053324.738100-1-baoli.zhang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The original implementation caused an out-of-bounds memory access in the sdw_add_element_group_count for-loop when i =3D=3D num. for (i =3D 0; i <=3D num; i++) { if (rate =3D=3D group->rates[i] && lane =3D=3D group->lanes[i]) ... To fix this error, the function now checks for existing rate/lane entries in the group(a function parameter) using a for-loop before adding them. No functional changes apart from this fix. Fixes: 9026118f20e2 ("soundwire: Add generic bandwidth allocation algorithm= ") Reviewed-by: Bard Liao Reviewed-by: Andy Shevchenko Signed-off-by: Baoli.Zhang --- .../soundwire/generic_bandwidth_allocation.c | 47 +++++++++---------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/sou= ndwire/generic_bandwidth_allocation.c index fb3970e12dac9..f016ad088a1db 100644 --- a/drivers/soundwire/generic_bandwidth_allocation.c +++ b/drivers/soundwire/generic_bandwidth_allocation.c @@ -299,39 +299,36 @@ static int sdw_add_element_group_count(struct sdw_gro= up *group, int num =3D group->count; int i; =20 - for (i =3D 0; i <=3D num; i++) { + for (i =3D 0; i < num; i++) { if (rate =3D=3D group->rates[i] && lane =3D=3D group->lanes[i]) - break; - - if (i !=3D num) - continue; - - if (group->count >=3D group->max_size) { - unsigned int *rates; - unsigned int *lanes; + return 0; + } =20 - group->max_size +=3D 1; - rates =3D krealloc(group->rates, - (sizeof(int) * group->max_size), - GFP_KERNEL); - if (!rates) - return -ENOMEM; + if (group->count >=3D group->max_size) { + unsigned int *rates; + unsigned int *lanes; =20 - group->rates =3D rates; + group->max_size +=3D 1; + rates =3D krealloc(group->rates, + (sizeof(int) * group->max_size), + GFP_KERNEL); + if (!rates) + return -ENOMEM; =20 - lanes =3D krealloc(group->lanes, - (sizeof(int) * group->max_size), - GFP_KERNEL); - if (!lanes) - return -ENOMEM; + group->rates =3D rates; =20 - group->lanes =3D lanes; - } + lanes =3D krealloc(group->lanes, + (sizeof(int) * group->max_size), + GFP_KERNEL); + if (!lanes) + return -ENOMEM; =20 - group->rates[group->count] =3D rate; - group->lanes[group->count++] =3D lane; + group->lanes =3D lanes; } =20 + group->rates[group->count] =3D rate; + group->lanes[group->count++] =3D lane; + return 0; } =20 --=20 2.43.0 From nobody Mon Apr 6 09:33:05 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 97EAF2FFDFC; Fri, 20 Mar 2026 05:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773985316; cv=none; b=rqXkNCBk8wHKg9bdEdwqI7GZh4/dWPsGMG6vnvwzLInleiPJHrmrzAtrCGhjcm0a/NDdNRRKmROj1mjnCKlatM/h6eRyf49Y8vpEXcEZQ0b2DmLI8UZbnPyk/99zU2vaS8/s2ShcVb92+fYWOaz6ijNavuTk9W3W4/JSyqmMgRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773985316; c=relaxed/simple; bh=XFhp6S1cAiqrXnJzQlhjP9WkWfNi2K0bhuJI93iqy4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUi2YvOoCQEKaY/GP5RZjlCkV0l4VxPNZDcFXAN85YaRD7n7r6ernX++WD1RcXAx748+aCEhcAo+bNnz07THNh0+6nOzMQa3HNDELBKasv/BaaCozQT0dwfQ9qkemINH8BM8FhTKjZNeZbdLzwLwEPvsUFV7iiPlPMZyR0YNmLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lBi/zmtF; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lBi/zmtF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1773985315; x=1805521315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XFhp6S1cAiqrXnJzQlhjP9WkWfNi2K0bhuJI93iqy4M=; b=lBi/zmtFt62aW2CcfVQuONruH21ySKPyHe+5EJe+urZ+lVFiADPE3KUS CYrQpZtrtXJZPl0q3f9Y8lEzSB74lG5eJy0IshfxIO2KEx540DWML5oV3 JJytyMmcoTU7d70b4ofDX0DGiy2QOUze4QPAxy9mgQq/7JzR5XHY2E3P3 Um0TlbD5JS2Xwi52OGUZtB5Xc56YNu/ReOPOc36LODIcS2fKrgo8SqkWc GbH6Aor14uiDxuCkAXS0Ej7pak0+8DWB5CHmmrW5zvlqzLSjqIk+oTA29 itS64pv84JO9kTUaGKbXtjyQqLFYkiwkhPybGTzf5IXgDZIfmUuVd/jKS Q==; X-CSE-ConnectionGUID: E8itpISJTNqv9LUpcdD9Vw== X-CSE-MsgGUID: dg/C7LNbSRKXK29PL5whgg== X-IronPort-AV: E=McAfee;i="6800,10657,11734"; a="62629463" X-IronPort-AV: E=Sophos;i="6.23,130,1770624000"; d="scan'208";a="62629463" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2026 22:41:54 -0700 X-CSE-ConnectionGUID: Fl1NrjuWRfywsEKwcns+DQ== X-CSE-MsgGUID: AtPykEvdTTqCVSp2ILPdtQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,130,1770624000"; d="scan'208";a="223404415" Received: from emr-371.sh.intel.com ([10.67.116.154]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2026 22:41:52 -0700 From: "Baoli.Zhang" To: vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, perex@perex.cz, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Baoli.Zhang" , Andy Shevchenko Subject: [PATCH v1 2/3] soundwire: increase group->max_size after allocation Date: Fri, 20 Mar 2026 13:33:23 +0800 Message-ID: <20260320053324.738100-3-baoli.zhang@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260320053324.738100-1-baoli.zhang@linux.intel.com> References: <20260320053324.738100-1-baoli.zhang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Only update `group->max_size` after both allocations succeed to avoid leaving the group's state inconsistent if one allocation fails. Signed-off-by: Baoli.Zhang Reviewed-by: Andy Shevchenko --- drivers/soundwire/generic_bandwidth_allocation.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/sou= ndwire/generic_bandwidth_allocation.c index f016ad088a1db..cd9ccbaf0e46f 100644 --- a/drivers/soundwire/generic_bandwidth_allocation.c +++ b/drivers/soundwire/generic_bandwidth_allocation.c @@ -308,9 +308,8 @@ static int sdw_add_element_group_count(struct sdw_group= *group, unsigned int *rates; unsigned int *lanes; =20 - group->max_size +=3D 1; rates =3D krealloc(group->rates, - (sizeof(int) * group->max_size), + sizeof(int) * (group->max_size + 1), GFP_KERNEL); if (!rates) return -ENOMEM; @@ -318,12 +317,14 @@ static int sdw_add_element_group_count(struct sdw_gro= up *group, group->rates =3D rates; =20 lanes =3D krealloc(group->lanes, - (sizeof(int) * group->max_size), + sizeof(int) * (group->max_size + 1), GFP_KERNEL); if (!lanes) return -ENOMEM; =20 group->lanes =3D lanes; + + group->max_size +=3D 1; } =20 group->rates[group->count] =3D rate; --=20 2.43.0 From nobody Mon Apr 6 09:33:05 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (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 608FD2FE56F; Fri, 20 Mar 2026 05:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773985319; cv=none; b=L8JIC2WqnmiT9rtKmI6aQSF8plpTeiCvgxP8/qNX12/sBsiP3Y6cRWX+8gqR0i4zmEbZldKYbfE2B5pGvAhn0RqbqMjQkp3GA71jATllZ2mC5/MFdfFnv+tUGuHobcDos9JIhx8uFRYu+0xF10ru77WwSfAXi5icwCkPVZb/9/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773985319; c=relaxed/simple; bh=ThzEOhRRT54gJqLh3zwexBjVwMng+YpBwXs9GLFsjKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I5zf7BQtd4/wyXG/VY5Rm5hFqvqgAN58oSkmNhLsSDPWZr2NL12dwwbSQLQMNsL7Bps+jUHdBqMFrNLm1yN0FlBK7NZl0brObsRCW5NaevroynV9USO7yl25lJKMDzYLCl0T5OYc3pSsHAtdGaOsTocXOQFfdvH8GkYyNfH0WEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=D5CTRVjZ; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="D5CTRVjZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1773985318; x=1805521318; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ThzEOhRRT54gJqLh3zwexBjVwMng+YpBwXs9GLFsjKk=; b=D5CTRVjZtKzmr0Y2i7oqE8cbCZDeR1FAzfLOOth9py/aai6wnAbR9GmI Md68U39/4+ULXYUgHUU1cIo7pHFSWa0nbzfojCLjizzVSpobTkHauFbyR zWgjVGNPAT40tZC0G/uwZNdeZJmOG9mkF0KaBjWMxH0QCiZxJq2V/Jxu6 C2rFDLxxOLhOkWJYK1RnGFmfDLfgQsEVSNaR2w4GPX7qjxgWGJZ1o22h0 UcBaS3W1wIvLUcTxUtAODxQHzdq72wPBCBlDws0reFl3pWWg4GnWGtzDH yCKt7sVPOE84DXKREtL/C0kFq1ausoPsU/1TFi0HX+ats+bKHnz26WvUk w==; X-CSE-ConnectionGUID: 32lMruNkTFqdJif2u96H2w== X-CSE-MsgGUID: 607JAVtbSI68huIAcMnFYg== X-IronPort-AV: E=McAfee;i="6800,10657,11734"; a="62629473" X-IronPort-AV: E=Sophos;i="6.23,130,1770624000"; d="scan'208";a="62629473" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2026 22:41:58 -0700 X-CSE-ConnectionGUID: at1kntsPSgqCTSdX4RyAiA== X-CSE-MsgGUID: YlQetWuUSvW8D5tnBEMLDg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,130,1770624000"; d="scan'208";a="223404426" Received: from emr-371.sh.intel.com ([10.67.116.154]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2026 22:41:56 -0700 From: "Baoli.Zhang" To: vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, perex@perex.cz, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Baoli.Zhang" , Andy Shevchenko Subject: [PATCH v1 3/3] soundwire: use krealloc_array to prevent integer overflow Date: Fri, 20 Mar 2026 13:33:24 +0800 Message-ID: <20260320053324.738100-4-baoli.zhang@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260320053324.738100-1-baoli.zhang@linux.intel.com> References: <20260320053324.738100-1-baoli.zhang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace the use of krealloc() with krealloc_array() in sdw_add_element_group_count to mitigate the risk of integer overflow during memory allocation size calculation. Suggested-by: Andy Shevchenko Signed-off-by: Baoli.Zhang Reviewed-by: Andy Shevchenko --- drivers/soundwire/generic_bandwidth_allocation.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/sou= ndwire/generic_bandwidth_allocation.c index cd9ccbaf0e46f..3575d69ce1c50 100644 --- a/drivers/soundwire/generic_bandwidth_allocation.c +++ b/drivers/soundwire/generic_bandwidth_allocation.c @@ -308,17 +308,15 @@ static int sdw_add_element_group_count(struct sdw_gro= up *group, unsigned int *rates; unsigned int *lanes; =20 - rates =3D krealloc(group->rates, - sizeof(int) * (group->max_size + 1), - GFP_KERNEL); + rates =3D krealloc_array(group->rates, group->max_size + 1, + sizeof(*group->rates), GFP_KERNEL); if (!rates) return -ENOMEM; =20 group->rates =3D rates; =20 - lanes =3D krealloc(group->lanes, - sizeof(int) * (group->max_size + 1), - GFP_KERNEL); + lanes =3D krealloc_array(group->lanes, group->max_size + 1, + sizeof(*group->lanes), GFP_KERNEL); if (!lanes) return -ENOMEM; =20 --=20 2.43.0