From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) (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 16A3D3A3822 for ; Wed, 29 Jul 2026 09:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785317124; cv=none; b=ewx6u/iQ3DLSD7S0t8+Zm8trQFkS6VXwjY+hby9EDN0lX+HXyTY///LbVin2vV3s7St9Y+X7qS27sYet+4y35kVQ4PQb6n3hYvcUXiy6hc2LI9192j1tbjCWWMQd921N+ho0zVoe5lwY1jD+KOJAXsMsO0dEQbRh2FRhgKmwj5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785317124; c=relaxed/simple; bh=rWOsabcZC/idbWGwSUoOfylz7D8tdocBDLaDyREz14M=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=NlDd9F66a2ZjuowzNQmikLvqRhHYuiRJk/xW7YH+G8MHQGivJluWUHce+griGlXWGL7lRVlX8mD0o3YhMqXqBRbNMXlFszQk2GyvVC2+z+5PY6vMeR0CGMwvhT4yVPns+/1lZMkgINcpsE1BySrvpq3cb2ExYDYePpLF1nuCf4c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.167.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-495b8120909so751393b6e.1 for ; Wed, 29 Jul 2026 02:25:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785317122; x=1785921922; h=content-type:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=kDMvybIBL6UHWU+UZqsFntBmBWXuVyXA3Z40j8mDDsI=; b=YXAbbinhI0TjA+b7w1GnuNu/pggaMlc+ewQQ4PyFQ0ULSI3Fve5FwlgBGTfKIa6EK9 tkXH8javFZwUhGDRxXsIW/e35ju0azmE1oQIGOn1yuj2tnxNO5CXbtLXXoTFtLmrkujA kOvthENHP07avoMqqqlkn+jJMeKybi+IinTZMfiECntS7hCQTATaXLWlEXFie4nzwovv LUpQ7vSy5JiofXEcP45aS6CD66ky/uX8ro8HMyTwCR6jXOvduY+edi6qzxTlRptGbyuc 6eyNo/JPPZ/ESCuv3eeEHPHLjkiWX9B1kh3gaRjAXxZtJuskQyJ/rgQD5uYhwLcxO8fF GQlQ== X-Gm-Message-State: AOJu0YyldD2Kn/6WYaVNEUHG3fYtKHbpEraPoE7k7Pn+PQq/MvPKx1I4 l4zdUbGXHy/16tF+WM8j2J7fXaUl9Q0cncchInT2uP30cgQU+pxoHK/Ze6iVCmnOi2H4NLFcrBd 1hhMBK4G87Lsxs9QQU9732x1MGeUYhnW6QWsx//Q4JAkRh7u1C1tdjEFwduk= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6808:e84:b0:4ab:2256:a3fb with SMTP id 5614622812f47-4ad5bb24a23mr3417000b6e.26.1785317121955; Wed, 29 Jul 2026 02:25:21 -0700 (PDT) Date: Wed, 29 Jul 2026 02:25:21 -0700 In-Reply-To: <6a698f41.d9e86bb5.297b12.0051.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a69c701.d9e86bb5.297b12.005a.GAE@google.com> Subject: Forwarded: [PATCH] usb: gadget: f_uac2: fix invalid free in UAC2_RATE_ATTRIBUTE store From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] usb: gadget: f_uac2: fix invalid free in UAC2_RATE_ATTRIBUTE store Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master The store callback generated by UAC2_RATE_ATTRIBUTE() parses a comma-separated list of sample rates by repeatedly calling strsep() on split_page, which was obtained via kstrdup(). strsep() advances the pointer it is given to point past each consumed token, so by the time the loop reaches the end label - either after a normal full parse or after an early exit via "goto end" when kstrtou32() fails on a malformed token - split_page no longer points at the start of the buffer returned by kstrdup(). kfree() is then called on this interior pointer, which is not a valid allocation start address, resulting in a KASAN invalid-free. Fix this by keeping a separate pointer, orig_page, that is set once from the kstrdup() return value and is never modified by strsep(). orig_page is initialized to NULL so that early exits before kstrdup() is reached (e.g. the opts->refcnt busy check) result in a harmless kfree(NULL) instead of freeing an uninitialized stack value. kfree() is called on orig_page instead of split_page at the end label. Since both f_uac2_opts_p_srate_store() and f_uac2_opts_c_srate_store() are generated from this same macro, this fixes both attributes. Reported-by: syzbot+a4f65284f1451010b0a8@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=a4f65284f1451010b0a8 Signed-off-by: Deepanshu Kartikey --- drivers/usb/gadget/function/f_uac2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 897787d0803c..4b403cb779fd 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -2012,7 +2012,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \ struct f_uac2_opts *opts = to_f_uac2_opts(item); \ - char *split_page = NULL; \ + char *split_page = NULL, *orig_page = NULL; \ int ret = -EINVAL; \ char *token; \ u32 num; \ @@ -2026,7 +2026,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ \ i = 0; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + orig_page = split_page = kstrdup(page, GFP_KERNEL); \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ @@ -2037,7 +2037,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ }; \ \ end: \ - kfree(split_page); \ + kfree(orig_page); \ mutex_unlock(&opts->lock); \ return ret; \ } \ -- 2.43.0