Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2616199pxb; Sun, 17 Oct 2021 20:36:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/ZJtwOhI6gNoE+mk2EasKukdRjh4E+n9W0md0SSLJbwqA+V/txyNjhCNByREvUp4ZnlyW X-Received: by 2002:a63:5544:: with SMTP id f4mr21430225pgm.431.1634528211317; Sun, 17 Oct 2021 20:36:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528211; cv=none; d=google.com; s=arc-20160816; b=KykIsisjq2d/eOOsSP9unKkjyEShJHGGc8uHsV3mDGRVQVH7R5YzommaCbRdKUDrY9 BTprVEgB+GgTrWl96nn0AQKCb/1Et6cizo/apxzPB/y8fjjbiUykMaKXIg8eqotv6zyf hknZxNGaHm6GfOVYbOEPCdLhBikDaxLX+HvJrmtYJ9ijpC3pAnQt0ZhJoGxslrv+BwTk xZedE2o0hHnUGbRQ3/P2Zpcss7n1SXkesA2TCcRKlnTlh1SFFxOduwCaWA2ab7Rfbq3v t36FP/jHOtEdl8jUUpRc9aInZcIlPIbiF0s5qVyIr+2LjOY20KFlBYvZosoWVVHH86sw 3DJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :subject:cc:to:mime-version:user-agent:from:date:message-id :dkim-signature; bh=64dWe06VAqs+AnAQ50Xh+TBOE1vcFdAoG61oJRkkXbM=; b=MkaZ7kTiTEPZRZTFCO82zdPrPiQ3J5vdnghoUWxK8Clp+YJr8ztjDMwytl+XSwxBeV imDhADVq5L2s0WYtaNWHiiSGuVRvX3y5qchGMFOKLqpicOj1heH0ld2gP5WVdzOYBlr9 cibQq5/49M2HZgjU8UuzPOXPtJrD0UX4wduRucw2LSu4x61hbYnmtYCrLI/AZLDvQCFz mwse6jP4+B4zkJiSfZHzvB5QKDZk+NqMorKe6qigS9Ohe66BFQ+186PtZ71Ah01tXUhU INEpBZQUN5+AwLVb5aXQ7HqbGxxaVzVYLskBDknlLJWlMx/ceqT2kmSjeXjVm8eXdKb1 dyvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RnxF1T2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si23354763pgi.213.2021.10.17.20.36.38; Sun, 17 Oct 2021 20:36:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RnxF1T2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238264AbhJPPqN (ORCPT + 98 others); Sat, 16 Oct 2021 11:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231824AbhJPPqL (ORCPT ); Sat, 16 Oct 2021 11:46:11 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27EB3C061570 for ; Sat, 16 Oct 2021 08:44:03 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id w14so50562291edv.11 for ; Sat, 16 Oct 2021 08:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-transfer-encoding; bh=64dWe06VAqs+AnAQ50Xh+TBOE1vcFdAoG61oJRkkXbM=; b=RnxF1T2M6ilM3R2JA2+nw4F8eMXWSJq88+lq+C57fBSJlkoBaVykAtd+xZQRhKVj3C 8zVmMDpjfZyfqO1hr7DkE5rJgpmlhTGrwZk2+B83v8+tLn+TbEdt1+bRicvrqYkk1KfA eMh+z83CfJM0Bt9L2YBxST7aWnk1h0IbIIUg7UQGgWSE4YuolM6mzVseuvGhHFU0HmXi 9MF1dI7sytu6P7RczJRHOXnSttkTJHZ/HnmyxhDuqaC2SpGOb/waB+7s1k7IL2aGwS4D yXuo0j90SvG2DLrvp69ejsjuH7eV1CMZhzSzjbm2A0LJiwVYjmgaB+YPsFQP/tFiKAaX acVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-transfer-encoding; bh=64dWe06VAqs+AnAQ50Xh+TBOE1vcFdAoG61oJRkkXbM=; b=Z0cO2Z4U4BUnhjqNRO4B23SLzy1Tcu/g1x1yhGQiQkxfJ27YL6lEbkoEF3Ei7tmVu/ l/I4xr8pqfVvRKyACzE/IocIsmNj3IQiDeg0Dyiq1cy42CdS68VGmV6RydwPN/tAT/Ib sBeV6VHYw7QVLwZcDVxq+YQbPrPkeXc02B6FRvrALskDZtbji9fJ/DRdW/nDwO7SgQl4 XB7M0BUpDujsL8vDOg6f21GCLP/QyimrgkZac96okJ8p4/XOnd76+EujBFN31mCtAACT F85/Yn+CTe3a/Yr7AoSJGqDjAVaqGmAhXLMmtLzgZECZIC571v0JJcurTZXN6nWvObkO fNxg== X-Gm-Message-State: AOAM533WwHPsdpXsWb0/MBBLtivIeZo9pz0bp03AAPWXQNordUqSVxOr uawe39ylu8qAobSjgh1mf9o= X-Received: by 2002:a05:6402:35d1:: with SMTP id z17mr27977981edc.174.1634399041759; Sat, 16 Oct 2021 08:44:01 -0700 (PDT) Received: from [109.186.97.74] (109-186-97-74.bb.netvision.net.il. [109.186.97.74]) by smtp.gmail.com with ESMTPSA id n6sm6982504eds.10.2021.10.16.08.44.00 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 16 Oct 2021 08:44:01 -0700 (PDT) Message-ID: <616AF32F.1070403@gmail.com> Date: Sat, 16 Oct 2021 18:43:43 +0300 From: Eli Billauer User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100907 Fedora/3.0.7-1.fc12 Thunderbird/3.0.7 MIME-Version: 1.0 To: Ziyang Xuan CC: arnd@arndb.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] char: xillybus: fix msg_ep UAF in xillyusb_probe() References: <20211016052047.1611983-1-william.xuanziyang@huawei.com> In-Reply-To: <20211016052047.1611983-1-william.xuanziyang@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Correct. Thanks a lot. Acked-by: Eli Billauer On 16/10/21 08:20, Ziyang Xuan wrote: > When endpoint_alloc() return failed in xillyusb_setup_base_eps(), > 'xdev->msg_ep' will be freed but not set to NULL. That lets program > enter fail handling to cleanup_dev() in xillyusb_probe(). Check for > 'xdev->msg_ep' is invalid in cleanup_dev() because 'xdev->msg_ep' did > not set to NULL when was freed. So the UAF problem for 'xdev->msg_ep' > is triggered. > > ================================================================== > BUG: KASAN: use-after-free in fifo_mem_release+0x1f4/0x210 > CPU: 0 PID: 166 Comm: kworker/0:2 Not tainted 5.15.0-rc5+ #19 > Call Trace: > dump_stack_lvl+0xe2/0x152 > print_address_description.constprop.0+0x21/0x140 > ? fifo_mem_release+0x1f4/0x210 > kasan_report.cold+0x7f/0x11b > ? xillyusb_probe+0x530/0x700 > ? fifo_mem_release+0x1f4/0x210 > fifo_mem_release+0x1f4/0x210 > ? __sanitizer_cov_trace_pc+0x1d/0x50 > endpoint_dealloc+0x35/0x2b0 > cleanup_dev+0x90/0x120 > xillyusb_probe+0x59a/0x700 > ... > > Freed by task 166: > kasan_save_stack+0x1b/0x40 > kasan_set_track+0x1c/0x30 > kasan_set_free_info+0x20/0x30 > __kasan_slab_free+0x109/0x140 > kfree+0x117/0x4c0 > xillyusb_probe+0x606/0x700 > > Set 'xdev->msg_ep' to NULL after being freed in xillyusb_setup_base_eps() > to fix the UAF problem. > > Fixes: a53d1202aef1 ("char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)") > Signed-off-by: Ziyang Xuan > --- > drivers/char/xillybus/xillyusb.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c > index e7f88f35c702..dc3551796e5e 100644 > --- a/drivers/char/xillybus/xillyusb.c > +++ b/drivers/char/xillybus/xillyusb.c > @@ -1912,6 +1912,7 @@ static int xillyusb_setup_base_eps(struct xillyusb_dev *xdev) > > dealloc: > endpoint_dealloc(xdev->msg_ep); /* Also frees FIFO mem if allocated */ > + xdev->msg_ep = NULL; > return -ENOMEM; > } > >