From nobody Thu Jul 23 21:53:41 2026 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3AA727603F for ; Wed, 24 Jun 2026 12:43:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782305040; cv=none; b=gN6XnURuLalYohkN/Rlb52ZuQ66+2msgudOBh2gmn0vI0EbU/6NL+//MdN6PTWlU5+xz8rIBz5NRRBGB42dNX4f0LlKIs0iYAzKQXOP2S/S/f6BpxD614tCfrYYXzOo8Nmyk7aQcaC79gUsDAJCcFEkeUmHZHAaKUbUMXqxG0Nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782305040; c=relaxed/simple; bh=TkkkpltfwLYAs+4DkGuuzvj8KpFUCTvhW7KGfueohTc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SRIHddMbdJ3QMRatg+UDdJYU736iST145tGzAzOmqR4Bin4mbt2gnEyf8pfZpeaCF+NdxwFvFDaFpARzuph1343ty2z23pn0xkmQPwIOKv8qy0bw5oX4PQ7tV74qa/5DikgDgA/1rYVB7c7PP9mR+wmTEDFMtjBTwYE2QXnJssU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pIU/QpHe; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pIU/QpHe" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-46cf972f281so87276f8f.2 for ; Wed, 24 Jun 2026 05:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782305036; x=1782909836; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lZSBOgiOu98VSFfL5hE8Rxx3Hlc6Tda5ZxDJZ0F2Ebc=; b=pIU/QpHey7E2+r3o2FgS3qyszVvLwCUexGNKjRyAgTlPQxr//DnxmuaKh3Ah2haq/Z d/VnR2PpgeiCTC9j2KzC/wM6LhJGLuoBD/n9wrckYuzttYYijwhJz4tWqHb24TwnaziB 5gh3+QoU9P4hCrnhPJYo/lx+CpDNOB39LjBNV9to/pA3WLFvjrtx3un2rKoB7utZDDni J5/NSKLu9cSJCBRXsfEFnHsRjelQdw1kuI5Aigd/ruWFCDOZc5YzbcqUwTZ+5nLOZVCS a1/pxVHToqVa7LUqMdP4Vp1ebCE1O2dHEyT06W03fK6NC9ZnP0P+XCHcJiveV1hxa91g xnCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782305036; x=1782909836; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lZSBOgiOu98VSFfL5hE8Rxx3Hlc6Tda5ZxDJZ0F2Ebc=; b=KyfccmgU7TumzHjK+TtGDP6b617+V8DT8UhQdvxBdYuNy/1/qNHatPbKlHonChURRx 0b7e5p2DTpoi3vFGgxxlU2xsMekey4pvqNXuNGsI5cw4EGls2NnhMuSG1OENBhT7TExL c6kCqbCuWWUZ7OOU5Hj9md6nNaAHIrAGJATteMXi7HUS3ySBmAVnzMh35X5LHjmFqDLC XcN0rSAaXWPRobus4XXiwo5K5A9rMlpgNCs35uF1j4SqzwgIERFMRMtR1SJF2M0P4yKR 6iDD1+JqnWycrt1D3QtTCp/0eIyL/4m2I8agmJV+YSZly20mXERTKk+sOdEFCMLMQ/7P uN1A== X-Forwarded-Encrypted: i=1; AHgh+RoSMnYBOPGKRkXs7G5sxy/p63GEnXJrK0CKyzeWp/TMchqQ7m72aPvBvupLcjEWwzgE5qBHSbJe49mJ4sU=@vger.kernel.org X-Gm-Message-State: AOJu0YykmI36NzmqBmWJ3GZCl3S0/bovSVwPHFlR/2EBbbjkAywVS9gW fa4PSS9RcUEjY1WjqzB1/ovzTBfUqWHvB/OYkgVlDyixzekhfTXstXR2 X-Gm-Gg: AfdE7cmfm5lL9GVdqEJEFRB8rh0sysgOo6BCOmkWj/YEscQKUSEDaljXqmPBAONHijf IZs1PzOV/I7bJI9iBIRgqWuwh5oHsPjfaX8gC9cyhoL9+jD6gYmtEBgoOv00P9GZn2GImhjNPMM w8eO6lUCR/YELqoBKk7hOVBnLbjSWh0kSh/R2HeG8+4eCTENqAgYIWdRauv3Gm6YIU6rVoGbDDn u496bUu4GTwKdyIs2/bnIxeO/W4J8awMk/PsOUcmYrqWA149BTNRwyTz58WRliIg+lZPbtMEIEY 0yBUi0QaCPrQmpTGN7dn1vPwmi5tmiXSACS7gqf90i19zUZuIkWEr3HFNO/jvUlIX0o4pKALkAq CSCCh4H6ksERreRp+NdSVBRzcEWoQFZyhj1DR3McEcxJiKQmJ5rxgBFVf8dEGARSKSipuICq+nW L8m4xvrrZBJIa2FzTBT6yoTLZcqw== X-Received: by 2002:a05:6000:2f85:b0:43c:fa96:d939 with SMTP id ffacd0b85a97d-46c06ad9caamr5500865f8f.22.1782305036000; Wed, 24 Jun 2026 05:43:56 -0700 (PDT) Received: from Dev-Null-MSI ([2a0d:3344:52ac:a808:98a4:4381:be45:536f]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-46c226a6f13sm6230010f8f.26.2026.06.24.05.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 05:43:55 -0700 (PDT) From: Yousef Alhouseen To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Yousef Alhouseen Subject: [PATCH] xenbus: preserve terminator when splitting directory strings Date: Wed, 24 Jun 2026 14:42:42 +0200 Message-ID: <20260624124242.9160-1-alhouseenyousef@gmail.com> X-Mailer: git-send-email 2.54.0 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" xenbus_directory() gets a reply buffer that xenbus_comms.c null-terminates at body[len]. split_strings() counts strings using that terminator, but then copies only len bytes into its combined pointer/string allocation. If a malformed or unexpected directory reply does not carry a final NUL within the advertised length, the relocated last string is left unterminated. Callers then treat the entries as C strings and can read past the allocation. Allocate and copy the transport-added terminator as part of the relocated string block. This preserves current parsing behavior while keeping every returned entry NUL-terminated. Signed-off-by: Yousef Alhouseen --- drivers/xen/xenbus/xenbus_xs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index c202e7c55..05b758fff 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -420,13 +420,13 @@ static char **split_strings(char *strings, unsigned i= nt len, unsigned int *num) /* Count the strings. */ *num =3D count_strings(strings, len); =20 - /* Transfer to one big alloc for easy freeing. */ - ret =3D kmalloc(*num * sizeof(char *) + len, GFP_NOIO | __GFP_HIGH); + /* Transfer to one big alloc for easy freeing. Keep the extra NUL. */ + ret =3D kmalloc(*num * sizeof(char *) + len + 1, GFP_NOIO | __GFP_HIGH); if (!ret) { kfree(strings); return ERR_PTR(-ENOMEM); } - memcpy(&ret[*num], strings, len); + memcpy(&ret[*num], strings, len + 1); kfree(strings); =20 strings =3D (char *)&ret[*num]; --=20 2.54.0