From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796039459; b=Gx3EWj5ySXVyxDKuhvTLURLbBmW2FFtsKPBVUOeULW++4zQqkIXYOL3kukpTVTv0fCT1 g0+lqS0nxMnQRNk6tvQ0BjwuZr/JgLJ1CQBWE9ocJpKsDilqyK7XNGZgmkuU/v/uzy4hl hnx9T7gV23QzVAVQHnGw0WMc0RyeiCozrCussOBTkvUnrCLAvQ2lNr+aYW0NmvIyecicq jk9G2BaZF3XbCn+90q5g/8lNQGW8OI7V90KkZ0ocAhWBwzTitIvK2+WQdjbaWpfyVpEdU L6o1LOk7WzlTBjpKXRVz/mF+mca3N25PaS5hoER2VLDtwpNDtnd5SKLkItQBZQFeJYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796039459; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=9YJOVsbo29z5nzigmGldqmUKsTKk+1JNvhSuUTlhjU8=; b=00VfTOnURU6BNutTraTn6p4cC6QnK4JAEXvkq2AYmhlagBLbQoQz4vY/Sw4mT3INke85 wwIITYlI5YoN5PQw99A3ME+qYW9B/zrfJ3+3GHDL0TJEwLsS++a2KIeNx/5PxxPM/yuCB VbNOQ9aEvayEAULvhN7C9TgHkY6OXeU5xlkWuU+IxTO3lb1pcfYke/Q7jmIh8Rs/hKLU6 I/BTCwZlCeCDaMk4zGsLNhWn59fdiT0tzoEvK30FUb5k5jm/MLLROEoXNLrCOXiQ2AbZH Sti8p3Ybd2p8T3K2KZ0FRNeyckrb4+hrqx9cJtARRZgnCyn/S8/aeCNAHxQBF7ELF4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tcSFPXRl; arc=none smtp.remote-ip=209.85.215.177 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16C40606A320 for ; Mon, 30 Nov 2026 11:50:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16C40606A320 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.a=rsa-sha256 header.s=20260707 header.b=tcSFPXRl Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-ccca948203aso6920279a12.3 for ; Mon, 30 Nov 2026 03:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796039458; x=1796644258; 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:content-type; bh=9YJOVsbo29z5nzigmGldqmUKsTKk+1JNvhSuUTlhjU8=; b=tcSFPXRlzej+XSTXRU+ewiA1fudo0m4v9t3wDzQ0q4roZz5Tf7JwgX2k93sQx+jC/M aA95lkKjKTxGDJK6m7AlMc//u58SgboBtwEGLv4LEqyUrM+xKt6eM8mEo2/MZymeZMRE tH6HsLja64y4GzVh2VJacnQEHlxb3bxPjMXuHAGJxFloCm9nLa5R+WXSC9UymF9lRbys Pafy7lvAq/d5F5enuh7uGalU1oCGt4SX6f5xudpcrXk1YUz+O01v423Vn9xQVffXijyN bkjZ36B4EdrtF+4S2p/AFPH0DpNNetvWz0gFfAT9S5V41aodIaZ0rOSlNdynP/S18WXW QpnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796039458; x=1796644258; 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:content-type; bh=9YJOVsbo29z5nzigmGldqmUKsTKk+1JNvhSuUTlhjU8=; b=UxqMFkxmB5XgCh3fYJhLxGNnhq6jbRMVLO7xI3EJfME9XYfQrwA1fwLLLZrh8o6A0/ yHn/NRuI1XjNQGoHrxhoOny2lplypIRE0fIT8DRVPwhLVKBu6o8cu2/dV1ibltTi+gEb zNxw9EW1si7B5q7RWID2VolYdb6Jhz4RRkVC3KQoydSvpK9iW9Pi+L6kSQETcb6ubrlv wFKe5P0csay/5ZpPPzLuJadSERCQNBfOoKM443bRElsqUpJVMSoq3lKb8yqpaN0Cws0s IZNVAkWMBiFint9/4nCews3cYeBzjBL8nXG1WYOoEP2LAobbrvEYOpaeaG7Co8N3+Iu/ VFkg== X-Forwarded-Encrypted: i=1; AL+hErFCIgYxzwsMPbO832k9tsOe2wfvy70+9GwEQjP5RktYPOZof7bMQOAJx+hWdmwyyH9xTgWCgBt0R+c=@vger.kernel.org X-Gm-Message-State: APuU4Z+SCK8SRfi6D2GZoArX0E8bW6ghnTC4BHLr2ldllvYlQTW0+4GZ eBzwsfEdIUznjFiliNCkm/ynH44KdhxZXWqzhdFkSqY67u8NDI6ZqGr8 X-Gm-Gg: AZFdTZc4+H6HZQNM33ElmbcmmFUywwV2eXdQwoC3dCGhzoNEyGGi2vsKtdTD0Rf6xbZ Tjw66aX7UIqB6Jw/6i4+H0rT+MlRDauvLCMfAh/5kRJRcAdZZSbPVw1Co6olnnUZaGfuyEKXWIR yOJVqH3xkVHGzzed5ZhLkVuAD10BTYye/mW7MNy2qVKvYfrjmpXRV6R1DwQgJ5igbgU8+v9ElxW +NLZS6ch+dyLziPLuWg5cM0fcMtfqo2XvXuJ3m7MZLoqzjlJyLwAcHFrJQqS+tbGTsvu1OAgBLy vTm2f7HCIUtCd0EhSDG2DK73GepH6Tl52W5DMlbDFoH6MP0rFvUk8hrcglznZMP2S0nPPvG74g6 BhoMZvcXnsjbNb9rf+et3KLa50Vq3fz6rbOpvwVGBC5WxOsBT6W1dgfjU1spM2LKaRAouD6GYev HWUcf7/d5+8wA5Kyzn5jSDbKCk/fme98TrycCpCgyQLuWFU0uzWaERjuSx9aATuxTUKJ2IKosfL VKrjzaFIlu6KUIPoxnU6tUb8N++PwTB0rFNXWnlmdlV7e1ylSXPIiNj92WXOUm1IkAQtPrO/9Ky I3zd5xpWHKc0cBrUvV1PCkzFTk9dMxlJFPkKS6zFgp5bXCgnbNOioH2XPUylsEV4S1l9ZUJNunN RhKu/ujY= X-Received: by 2002:a17:90b:2516:b0:3b4:c9f8:abce with SMTP id 98e67ed59e1d1-3b4c9f8abe0mr15842496a91.35.1796039458107; Mon, 30 Nov 2026 03:50:58 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-226-254-86.dynamic-ip.hinet.net. [36.226.254.86]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5639e13f7sm9765613a91.12.2026.11.30.03.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 03:50:57 -0800 (PST) From: Lin Tzu Yang To: Greg Kroah-Hartman Cc: Neill Kapron , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: gadget: f_uac1: fix return value of string attribute stores Date: Mon, 30 Nov 2026 19:50:55 +0800 Message-ID: <20261130115055.842820-1-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.1 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The configfs store for the f_uac1 string attributes (function_name, p_it_name, c_it_name and the others) returns the result of scnprintf() with a size of min(sizeof(opts->name), len). That is at most len - 1, so every write is reported as short. The writer then writes the rest again; for the last byte the size is 1, nothing is stored and 0 is returned, and a writer that retries on a short write never finishes. Each retry also overwrites the name with what is left, so the name ends up empty. With busybox in a QEMU arm64 guest (dummy_hcd), all of these hang until they are killed, and the name reads back empty afterwards: echo MyAudio > functions/uac1.0/function_name printf NoNewline > functions/uac1.0/function_name echo Mic > functions/uac1.0/p_it_name This started when snprintf() was replaced by scnprintf(): snprintf() returned the full length of the string, which is len. Do what f_uac2 does since commit 9499327714de ("usb: gadget: f_uac2: fix return value for UAC2_ATTRIBUTE_STRING store") and commit e60284b63245 ("usb: gadget: f_uac2: fix non-newline-terminated function name"): return len, and strip only a trailing newline, so a name written without one keeps its last character. Fixes: c1a371866db9 ("usb: gadget: f_uac1: Replace snprintf() with the safer scnprintf() variant") Cc: stable@vger.kernel.org Signed-off-by: Lin Tzu Yang --- Tested on configfs-next 2e0fad9d2eae in a QEMU/KVM arm64 guest with dummy_hcd and busybox: before, the writes above hang; after, they return and read back MyAudio, NoNewline and Mic, a single-character name and a 70-character name are stored as written, and writes while the function is linked into a configuration still fail with -EBUSY. I could not check the strings on the host side, since dummy_hcd has no isochronous endpoints and uac1 does not bind there. Build-tested with W=1 on usb-next. The same return value change is part of a syzbot RFC from July, "usb: gadget: f_uac: fix multiple bugs in configfs attributes", which as far as I can tell was never sent to the lists. This patch was written with the help of an AI coding assistant (Claude). I ran the tests above and reviewed the change. drivers/usb/gadget/function/f_uac1.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 7539817cd4..656be855e4 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -1649,7 +1649,7 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ struct f_uac1_opts *opts = to_f_uac1_opts(item); \ - int ret = 0; \ + int ret = len; \ \ mutex_lock(&opts->lock); \ if (opts->refcnt) { \ @@ -1657,8 +1657,11 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ goto end; \ } \ \ - ret = scnprintf(opts->name, min(sizeof(opts->name), len), \ - "%s", page); \ + if (len && page[len - 1] == '\n') \ + len--; \ + \ + scnprintf(opts->name, min(sizeof(opts->name), len + 1), \ + "%s", page); \ \ end: \ mutex_unlock(&opts->lock); \ -- 2.47.3