From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796039459; b=S1zfHmL/KHGCfm+O1HAmz7OJwCJt9yhkbXf+YFUsEvkJ2ItDS+gepLzrBOAkIOFQ5EgF x0pvhS4YujkuGxoTNfSYSk/RXuY4TFbOUdIV8CREqYmIhVd4r5OEkjjZSSYYSMsR4KSpP qELBiDcBQVbdP+DeGxEWL7bPqKtnk6OOp0XAlnJUTqhVfSrsjo6uIx8vwV5/aS3GAG2Ao V8nu1fWUQal0L4ICXrJVQ7z7Gl5l/h25tIb+sKE7AclN0UEdxC3A1AMatCDir15qea+ge SXRzXUVrbtxybQRutQenVVMRPu4CvDzHzBOrwxWPqnJBXUyPo+I6gxYIOV3hzTjLV6w== 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=IeBX3iZUe2Ccg5yBNDzPQMdxn/Q7WXd+qf810VzhQZ3ZmuOrl7UYefRw+IKyBl7l4VD9 I/KxBIH8pnVYArrsY3DHjmK9vzbJcAGEkzDQhq7zVvh/bJ7pqab7fsyvH63Q/RuTGId7B sifbH+xUNVhg56qDzPQvczJWuJiGfGkZPv6ccC4LOH/m1t0+TKBpvswE0a6DGDz/Ol1gi kiTqXOBACVxL/MyzUaiGZmf2lDd4wiXMEj3ljcnwItmhuG26sqYTg4M6ZqqmBFlfdBL1b JH3+ezw9Ob7ZBvWP+hfmfVc8DsdmI0ogq12mYzy22r9L7bYQzKP2Ece+QQBeZcXG3nw== 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.182 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 08C40606A31C for ; Mon, 30 Nov 2026 11:50:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 08C40606A31C 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-f182.google.com with SMTP id 41be03b00d2f7-cddac941ed1so4597155a12.2 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=0N6Qrk/x+/UpjNKdmVBduAKKLBwkS/jFII2X66kQqP8HAr+WZkUCfQVtV88fNU7rdh 7GdpeGpaSc+Lc6zHe1vL1U/HUIRR3Oqgv0/kGH+7c8hbQRbUzoi3kUgSnX/Qpcv8HHUF pYuzmXTDljcMg14wxMasBnql+o7Xmot7iDRNdzBOsEdVDU8eYcmw97ttkT5BBkIE9cz9 q/1Bbcgi6RgkUEetvbxkHNzRTVX9WnioYxwQ6UykPz+CocC0FoBB7SwHIi3on/0+GmMk 1DHudvDtCZrgOK00ZUf51pQeCRulfqFsOIsjGm2ybePIQkcjeeDxa7JGvr50BNLf+gIS d23Q== X-Forwarded-Encrypted: i=1; AL+hErGxiAIKxDEljD+0BWy3cSDwF3uo6QLG+R1N7PlPs07/OLMefb/smhY1cpNStIt5siWrNLm9cJGT0xi1W6A=@vger.kernel.org X-Gm-Message-State: APuU4Z/9GduMQ5q4Bfz8mC6AF5mNk13Zpgq9p84mnfh9LsnCHLhxf+P7 +xFGCPiMBCuoh1t4JjbNsFDqBM5kR2sORwcVNlH2/NxIbrwtHhTLAdNl X-Gm-Gg: AZFdTZfDIG00COf3sp0UrmKacXPQJj4MqI29S7SBewa1kDm6aHZVZGG87dF7scB53YO x8DbRnkeOaNKgFpKCkydJG+lUM6+wWgMK8fAinfzfESsThcVoFucNAJY0XYR5kBq8Dt1U9nbOFr SbBNqBv81ewYtVaVT1c7cOD+IU+2LFaG9GppSCg8ClfaF9P5U8vQUNicqPhtV/XsYBByW1ROYPk vV6AWa5x75+HP93aWEzNY6gorTU+UBFCUNpB9VwQHmjSanQ0KRl9m1oHNjcJyvTqUeSBB+5+fN8 PIQ1op9/8Nx50o0P5bKSpV07j76pZ8Kb0SKi9H34qYNhCU217ngqKytCVopaMWKpVUKqRtmuLRq nCHjk70pwrSwYOfC5XvXa1d349lLLZ4XPVvb3qajpEobL57EzlDoGMWT/G/HJ/CCZwVsH+H/IkO bIKI7WVy08v9oVxEpVsYesJvAGkaIbWM7JmBJB+MFO42YM9PCt0sCGHFqVcYIefE7PMVRuWnPw9 gYrhWltikBR81zfW3mWedPByMoXpxttK6JCbGqmj/DfwsBt/bmfKfYUYhtpKQZjIm6ZY18lClFR pRQ8t+vyRlhFCUm8DvjH8ivQG4CqshfYfCohsRosxLahPyRH1AlQSz8HPHzWMUfJMk/J9UOQGnv 0dFouQXo= 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-kernel@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