From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C3FFCB67E; Wed, 8 Apr 2026 18:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775673513; cv=none; b=YwG1m7ORWc9YAVCAs6h0z5mW59kOljRjC77VBjypewqZe3kZFl2SsowRlKrP97bdDKWG21d8u5Rr08+iXxMCk2Qj3g0qyhyukPJl2Y1Rbbn8knHv8Zb2iw+wWTsNNz1WZQDwTuM1QnJ3zAVvDyOy+U0dyH6LOdESrcVliv0gMZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775673513; c=relaxed/simple; bh=YDgBEwVC6KiLiLzhv/r/+BpvmLtYONXEJfl3ItUgqPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s6iCqYBR+5PAyWojUABbG3yHzvPvxwZ97Bq8to0XnTvNbFDkGAiLAW0Upzx7zs4N+e28/tDeM2fQNYnoLHGGb5eD6KX+6gzFAPvlWNRi44IjDf3Bxc6VFuh/XtHCz+CDhQ1WjUH/kPn/UdKJYmKcgqhqVAGgI3nQ3KLJxTw86Hw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VEhBT7ra; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VEhBT7ra" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B4C5C19421; Wed, 8 Apr 2026 18:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1775673513; bh=YDgBEwVC6KiLiLzhv/r/+BpvmLtYONXEJfl3ItUgqPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VEhBT7ra6EWlxP/HHLgW1K4dYDjJzPUZ0MPVPLghAYhJ10mLlNWXmBXwy0QDOi0qe 3ftqWjMyZCV3kE+D+Mu0dqH2ZWHLEssqtLbLLKcRwGLCzsx7j9y0v1gZL44QrFJszz 3RqIJSjXpA9oj+wAPTmX74r2AyqOY7w90Kqk0bhM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Taegu Ha , stable Subject: [PATCH 6.18 262/277] usb: gadget: f_uac1_legacy: validate control request size Date: Wed, 8 Apr 2026 20:04:07 +0200 Message-ID: <20260408175943.639191688@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260408175933.836769063@linuxfoundation.org> References: <20260408175933.836769063@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Taegu Ha commit 6e0e34d85cd46ceb37d16054e97a373a32770f6c upstream. f_audio_complete() copies req->length bytes into a 4-byte stack variable: u32 data = 0; memcpy(&data, req->buf, req->length); req->length is derived from the host-controlled USB request path, which can lead to a stack out-of-bounds write. Validate req->actual against the expected payload size for the supported control selectors and decode only the expected amount of data. This avoids copying a host-influenced length into a fixed-size stack object. Signed-off-by: Taegu Ha Cc: stable Link: https://patch.msgid.link/20260401191311.3604898-1-hataegu0826@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_uac1_legacy.c | 47 ++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) --- a/drivers/usb/gadget/function/f_uac1_legacy.c +++ b/drivers/usb/gadget/function/f_uac1_legacy.c @@ -360,19 +360,46 @@ static int f_audio_out_ep_complete(struc static void f_audio_complete(struct usb_ep *ep, struct usb_request *req) { struct f_audio *audio = req->context; - int status = req->status; - u32 data = 0; struct usb_ep *out_ep = audio->out_ep; - switch (status) { - - case 0: /* normal completion? */ - if (ep == out_ep) + switch (req->status) { + case 0: + if (ep == out_ep) { f_audio_out_ep_complete(ep, req); - else if (audio->set_con) { - memcpy(&data, req->buf, req->length); - audio->set_con->set(audio->set_con, audio->set_cmd, - le16_to_cpu(data)); + } else if (audio->set_con) { + struct usb_audio_control *con = audio->set_con; + u8 type = con->type; + u32 data; + bool valid_request = false; + + switch (type) { + case UAC_FU_MUTE: { + u8 value; + + if (req->actual == sizeof(value)) { + memcpy(&value, req->buf, sizeof(value)); + data = value; + valid_request = true; + } + break; + } + case UAC_FU_VOLUME: { + __le16 value; + + if (req->actual == sizeof(value)) { + memcpy(&value, req->buf, sizeof(value)); + data = le16_to_cpu(value); + valid_request = true; + } + break; + } + } + + if (valid_request) + con->set(con, audio->set_cmd, data); + else + usb_ep_set_halt(ep); + audio->set_con = NULL; } break;