From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (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 D9CB922D4C3 for ; Thu, 18 Jun 2026 00:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781743862; cv=none; b=fOGQJZHMPLQQrOZouXXXPw9veqZj0v9ThKwDqBx0QogW6hc1m67Ikr0/WsJuFWRvgkcpEXZDEpaP4+mG2ccuBfMKup1NcdIHaSl0sKj3tCZEUulF7tlL56zYXgAL2zn6sJPR8EKZiXYR6PQ1GAFC/yV36xa+fo05TO91AFRM8aY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781743862; c=relaxed/simple; bh=9K8qgk/LMttc2MgVGpvjYfByG6bYbc/nsrauWvt3a5k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=CLypzZ35kUj4pnFY7n47vkCAz7FosLPGKQevmfNTz5RUfyQXUwL4lfFWq6XNbp6MomdsF+VXczN0d7to//wZSIy+fQ34Pkcgug6eBL/9HgM5PrUqbRg1MSeKu//FHoVd89PxVScQXVOJ2aRy1YwC6UsorxK39ozQ3vlbV2SPz7g= 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=ifudc6/I; arc=none smtp.client-ip=209.85.160.171 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="ifudc6/I" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-51761d27612so4022071cf.3 for ; Wed, 17 Jun 2026 17:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781743860; x=1782348660; 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=7wO4sURN+GahEQcQ1tMouM3s3UB4GKLHDxd5/uWIVfM=; b=ifudc6/ITgQptEPy0NiFqCX092YNvUqPkBpxdbGY0mfVklEcx1S9J1C4pSa7LKlTMK eWilRCZQQTRj5kluNRZjvjGfcRpl2lwjd3h296jI5oL6VhNygiruM4YArWPX5vwtNv1q /89E/nfx5nCeQrptPkXRewXWgot1yV9q4AeNVzqYQ4m4GsKP4UV0+8f3hLGxiGKJdovm f2RLgptbTSJ7DNv+eZ1TJXKmScYEwOsPi7V9uoDVc/m7m9rpih6qthB4ZJTrFT3lqx6c BJoFfxfo336sak8YqnqZKsvjXtpm4U8XLtKl8EEhAzeTJbWl3pn8KuS1ylVpduHKg8Rj Z5Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781743860; x=1782348660; 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=7wO4sURN+GahEQcQ1tMouM3s3UB4GKLHDxd5/uWIVfM=; b=Y/kqkxtY8TzUbJgparLfu8w1215X8cZEsGqxmcJr5yO9EhmmOLH8tWhvoh5QNyPypC 69JlGvw+/dFe+fLsRZ5OQl/eLDVp5KaHGeaYpQ0IVMJGmKdzL7AlzlkAyLqak6jmHkp4 VAS9eFB8/mvDEbmRbOthx5g/Yl6nhKGiYtgU3LbWK7uj0+lYpWOio6usiCTd+5qSAA29 Q++8ErOmmkz0cBl1oSDMX12CIy4AjDTXJFXTAUY9C/RVEqEeYa9aEDhh2yLzzR8ros8K NoKqXrqXRJrbxrdqLL+TMO8GqN+9hvVQ89ZxTId/ESHIbWmSD/NdMrf8vzRVCNhrfRCh ui0g== X-Forwarded-Encrypted: i=1; AFNElJ/zZR+aTpmTifTNxZLa30inc02iagYYLEJAWR3FftOg/9ebFScBrkoqoJhtLbrN/XZ+D08ogN35VtF241I=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6FsOQlaaUL/VZDJ35U9RnLpzlUqxUt936JzX1o/wKcE2tzkJG V+JuFSJKCmkz3xEPyZl/GqY7ZnP30IuyN3XD4mAiF54F3j+Z3mdjr1WY X-Gm-Gg: Acq92OFxC4WA8F2ZVvs1h0HJ+gGuaiAtAtltDxQoxpSAKFt0HN3hckPJeBG4HFxCmLc eNh4WRc/tfMHDmr98iDSNi+yWQoHNZsS5VZV4rBRQFT4rCDaR/imKM+EW5HYQz8R16QpX3N+9V+ Q9S4tl2znQMdusJrocUcE1Yt1WDQt2mm73SO2arlCwll2uNL1JGTgHVg6kRIU2FrS8lJrY/9DCg Ijm4w/rOpX07m7TnRFcYhL/Es/pACnJ6IaM35a5u8A4BGb9In0NbA8HHNS6g8ZZ9hq9LaBu+dBb cpcez1qkOqE0KtyeqWFpbSM2qJaXM5+bT+p6HpXbri5LTyGdsgXFZmVS/W0pJS9hNTUq+sPnhbH ESXNc1nplXU4S91MUUt2TIn/QYXevq7aAJsK5dagg8cJSvtdIZpkyDza7oTzSXGCYP7CNvJDysL z2vhfe6iLO4QxYMrDOvQLBtMJvK8WfF1KfxEmdsNHJpPnCF9EaNqkmmIQvqIvkuVqYa8gkBtXyu Wep/6n9iEjEqbabAdeYZYVZrmULx/n0 X-Received: by 2002:a05:622a:1392:b0:519:5208:1fc3 with SMTP id d75a77b69052e-519a8fe823fmr98322311cf.42.1781743859800; Wed, 17 Jun 2026 17:50:59 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-517fb642740sm181646011cf.7.2026.06.17.17.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 17:50:59 -0700 (PDT) From: Michael Bommarito To: Greg Kroah-Hartman Cc: Stefan Agner , Krzysztof Opasiak , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: gadget: configfs: fix out-of-bounds read of qw_sign Date: Wed, 17 Jun 2026 20:50:43 -0400 Message-ID: <20260618005043.1581707-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit os_desc_qw_sign_show() passes OS_STRING_QW_SIGN_LEN as the input length to utf16s_to_utf8s(), but that argument counts UTF-16 code units while OS_STRING_QW_SIGN_LEN (14) is the byte size of qw_sign[]. The array holds only OS_STRING_QW_SIGN_LEN / 2 (7) code units, so the conversion reads up to 7 units (14 bytes) past the end of qw_sign[] into the following members of struct gadget_info when the stored signature fills the array without a NUL terminator, exposing those bytes through the configfs attribute. The store path halves the count for its input bound but passes the full byte count as the utf8s_to_utf16s() output limit; use the destination code-unit count in both directions. Fixes: 76180d716f91 ("usb: gadget: configfs: make qw_sign attribute symmetric") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- drivers/usb/gadget/configfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) Notes: - Build-tested: drivers/usb/gadget/configfs.o, x86_64, gcc, W=1, CONFIG_USB_CONFIGFS=m, 0 warnings before and after the change. - The over-read stays within the struct gadget_info allocation (qw_sign[] is an inline member), so KASAN does not flag it; the fix removes a read past the array bounds, found while auditing UTF-16/UTF-8 conversion length units tree-wide. - Behaviour: a 7-code-unit qw_sign stored without a NUL terminator previously rendered trailing bytes from the adjacent struct members; it now renders exactly the stored signature. diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 183a25f65ac89..dd6d6b11199e0 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -1177,7 +1177,7 @@ static ssize_t os_desc_qw_sign_show(struct config_item *item, char *page) struct gadget_info *gi = os_desc_item_to_gadget_info(item); int res; - res = utf16s_to_utf8s((wchar_t *) gi->qw_sign, OS_STRING_QW_SIGN_LEN, + res = utf16s_to_utf8s((wchar_t *) gi->qw_sign, OS_STRING_QW_SIGN_LEN / 2, UTF16_LITTLE_ENDIAN, page, PAGE_SIZE - 1); page[res++] = '\n'; @@ -1199,7 +1199,7 @@ static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page, mutex_lock(&gi->lock); res = utf8s_to_utf16s(page, l, UTF16_LITTLE_ENDIAN, (wchar_t *) gi->qw_sign, - OS_STRING_QW_SIGN_LEN); + OS_STRING_QW_SIGN_LEN / 2); if (res > 0) res = len; mutex_unlock(&gi->lock); -- 2.53.0