Received: by 10.223.148.5 with SMTP id 5csp7953899wrq; Thu, 18 Jan 2018 11:39:41 -0800 (PST) X-Google-Smtp-Source: ACJfBotQXyCKuLmPSnSlFWigiO3/D9N4ONYCLIJo34DGf9Pnf+EoRL2JVImaeUpsE0uJ+uhRnCzk X-Received: by 10.101.71.130 with SMTP id e2mr13356180pgs.396.1516304381547; Thu, 18 Jan 2018 11:39:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516304381; cv=none; d=google.com; s=arc-20160816; b=XvKMCWafIFb5CCTS5malferg8YKTjblujf26CHtskotdb2MvYVNAGEe/4XKJmcXWM3 YW6N6vVLUKlwCTlwq8eOq7nnGYMzmwOqZ6AN0DwzzBwnDYR0goytu34vggWXVe6TVL1e B8rdeunZ81WwoNZfBYmA4MqKoENTuM765riW090H88ZWlqjDeIP8d9QM/+ZZGTXqt+xC m2uV1odJ+wzJddoA+zDsodCoa8Ryg+1++jh5Kvxe9P2C5UszVkgYWIAg9FuSFLL/l0CV 6MK7zYEJy8zMTjhaijbqvaxXE2xjtzatTr1P4pNnh8tryqhfRZsmM7Lh7C/FJ7XKHG2t jjMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Rj48EbdhNh1FdGwcGz9+zwiV8SwnVVHIxRu11MLFnAY=; b=0DNxIEm6CfOzQh7arIJ2dd6K1sZPWvnanv++oderh4MDiaQc9TYrxAbAV/nNGHA1ss oogyu0UwJ1aApVB32TU8l+sKF0rsMYhLRurjNywrqebkdr0wcQOkLongatHYSiVRBpv/ 5kmfmBubPt8xHeuuiOtxXuYSU/8wmhV1L5/Wj3nP0AK3U7iXu9vtB8cGfT5FRFYFxzjz vkx2HnyV++Ymb47+oPL1zc+QFkD6m7dwsF6RqoeV/tRGpik2eWSz8XrafvqTCBeyGP+8 25hBka/xgBJY8dbLg1nVBf8z5fJbl7ZRTg0BMm+rJ9caJWp/3KJLEveUXJnsSS2qidQb FMQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d3nHMBP4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63si6714928pgd.540.2018.01.18.11.39.28; Thu, 18 Jan 2018 11:39:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d3nHMBP4; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932774AbeARTi5 (ORCPT + 99 others); Thu, 18 Jan 2018 14:38:57 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33085 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932728AbeARTiu (ORCPT ); Thu, 18 Jan 2018 14:38:50 -0500 Received: by mail-pf0-f193.google.com with SMTP id t5so9323758pfi.0; Thu, 18 Jan 2018 11:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Rj48EbdhNh1FdGwcGz9+zwiV8SwnVVHIxRu11MLFnAY=; b=d3nHMBP4fbQp33hVKFRDsU0ZRefGe9bnU5IGrS5uaS7fsIUfhKUDGmHh0O/q6I+3t+ q7P6GrJcnUnnO9hlImcHTys14Gy/3wMb12ALTi1XeCIxDgwGRpkT9v2kANnsV0BmUbae DoL+N3WnSxsIvbxCROT8XBSY59WmSCLla3D32J6W+VKXZ/mska/yg3HYKYFraMxiDYEZ P+bG3ZsBJJjqmZPBLOEARuRf8V4zR7eqUHF2lpr4jJ68m+t71IUO2HFHz9EcqsUsDx70 qgKNO3FOgknVnC21TyEtmRQSebNlxasy4uvdYQ2Hkiu+IkiNfnIR6usF/fe3IGrwK/f8 mFaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Rj48EbdhNh1FdGwcGz9+zwiV8SwnVVHIxRu11MLFnAY=; b=pKolOs0hNm1SwG8nP42Jfg5ux9U4EZCVZ6VClFxvdQWOQ+5oxN8+0X1IA7iEPoSP8l 4bOOf2bzCqCAEltcpNarwNi/iOcn+V9K3p+6y5e937UMb/gjDoGKj78sdmYH3nX+xOq+ GFt8UwcKg8FTCyEof8QDTfJBJL4AUlRqpiptHkIU+qpTulocuecgBZl68f9Z4z5INgK1 Um9DmdAuUSqZ2qll4DJDcCZKefXMz0vcVTy8++kkdBcXcUMRkaajWGiYGqrhyHvmFD9q zGyASIJBTZEgl+zoaaUWvWCZ1ImU3RnimwSI1XcvmLsm4P47MvSM4v5kPWwgqjCNtvg7 Yzbg== X-Gm-Message-State: AKwxyte8b6Hhcj5yI515K5X5iZdvXbQEcJB89bn+A5oTz4K/tSFxOQgP koQaKTpxdNk13rGWF3CA9M4= X-Received: by 10.101.102.73 with SMTP id z9mr15309883pgv.448.1516304329541; Thu, 18 Jan 2018 11:38:49 -0800 (PST) Received: from dtor-ws ([2620:0:1000:1611:da80:8749:c06f:9515]) by smtp.gmail.com with ESMTPSA id x8sm2702229pfk.123.2018.01.18.11.38.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 18 Jan 2018 11:38:48 -0800 (PST) Date: Thu, 18 Jan 2018 11:38:46 -0800 From: Dmitry Torokhov To: Nick Desaulniers Cc: Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, usacrc@yahoo.com, stable@vger.kernel.org, Benjamin Tissoires , Nick Dyer , Andrew Duggan , Christophe JAILLET , Guenter Roeck , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input: synaptics-rmi4 - prevent UAF reported by KASAN Message-ID: <20180118193846.bwotik7ngarpienm@dtor-ws> References: <1516170303-3963-1-git-send-email-nick.desaulniers@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1516170303-3963-1-git-send-email-nick.desaulniers@gmail.com> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 16, 2018 at 10:25:01PM -0800, Nick Desaulniers wrote: > KASAN found a UAF due to dangling pointer. As the report below says, > rmi_f11_attention() accesses drvdata->attn_data.data, which was freed in > rmi_irq_fn. > > [ 311.424062] BUG: KASAN: use-after-free in > rmi_f11_attention+0x526/0x5e0 [rmi_core] > [ 311.424067] Read of size 27 at addr ffff88041fd610db by task > irq/131-i2c_hid/1162 > > [ 311.424075] CPU: 0 PID: 1162 Comm: irq/131-i2c_hid Not tainted > 4.15.0-rc8+ #2 > [ 311.424076] Hardware name: Razer Blade Stealth/Razer, BIOS 6.05 > 01/26/2017 > [ 311.424078] Call Trace: > [ 311.424086] dump_stack+0xae/0x12d > [ 311.424090] ? _atomic_dec_and_lock+0x103/0x103 > [ 311.424094] ? show_regs_print_info+0xa/0xa > [ 311.424099] ? input_handle_event+0x10b/0x810 > [ 311.424104] print_address_description+0x65/0x229 > [ 311.424108] kasan_report.cold.5+0xa7/0x281 > [ 311.424117] rmi_f11_attention+0x526/0x5e0 [rmi_core] > [ 311.424123] ? memcpy+0x1f/0x50 > [ 311.424132] ? rmi_f11_attention+0x526/0x5e0 [rmi_core] > [ 311.424143] ? rmi_f11_probe+0x1e20/0x1e20 [rmi_core] > [ 311.424153] ? rmi_process_interrupt_requests+0x220/0x2a0 [rmi_core] > [ 311.424163] ? rmi_irq_fn+0x22c/0x270 [rmi_core] > [ 311.424173] ? rmi_process_interrupt_requests+0x2a0/0x2a0 [rmi_core] > [ 311.424177] ? free_irq+0xa0/0xa0 > [ 311.424180] ? irq_finalize_oneshot.part.39+0xeb/0x180 > [ 311.424190] ? rmi_process_interrupt_requests+0x2a0/0x2a0 [rmi_core] > [ 311.424193] ? irq_thread_fn+0x3d/0x80 > [ 311.424197] ? irq_finalize_oneshot.part.39+0x180/0x180 > [ 311.424200] ? irq_thread+0x21d/0x290 > [ 311.424203] ? irq_thread_check_affinity+0x170/0x170 > [ 311.424207] ? remove_wait_queue+0x150/0x150 > [ 311.424212] ? kasan_unpoison_shadow+0x30/0x40 > [ 311.424214] ? __init_waitqueue_head+0xa0/0xd0 > [ 311.424218] ? task_non_contending.cold.55+0x18/0x18 > [ 311.424221] ? irq_forced_thread_fn+0xa0/0xa0 > [ 311.424226] ? irq_thread_check_affinity+0x170/0x170 > [ 311.424230] ? kthread+0x19e/0x1c0 > [ 311.424233] ? kthread_create_worker_on_cpu+0xc0/0xc0 > [ 311.424237] ? ret_from_fork+0x32/0x40 > > [ 311.424244] Allocated by task 899: > [ 311.424249] kasan_kmalloc+0xbf/0xe0 > [ 311.424252] __kmalloc_track_caller+0xd9/0x1f0 > [ 311.424255] kmemdup+0x17/0x40 > [ 311.424264] rmi_set_attn_data+0xa4/0x1b0 [rmi_core] > [ 311.424269] rmi_raw_event+0x10b/0x1f0 [hid_rmi] > [ 311.424278] hid_input_report+0x1a8/0x2c0 [hid] > [ 311.424283] i2c_hid_irq+0x146/0x1d0 [i2c_hid] > [ 311.424286] irq_thread_fn+0x3d/0x80 > [ 311.424288] irq_thread+0x21d/0x290 > [ 311.424291] kthread+0x19e/0x1c0 > [ 311.424293] ret_from_fork+0x32/0x40 > > [ 311.424296] Freed by task 1162: > [ 311.424300] kasan_slab_free+0x71/0xc0 > [ 311.424303] kfree+0x90/0x190 > [ 311.424311] rmi_irq_fn+0x1b2/0x270 [rmi_core] > [ 311.424319] rmi_irq_fn+0x257/0x270 [rmi_core] > [ 311.424322] irq_thread_fn+0x3d/0x80 > [ 311.424324] irq_thread+0x21d/0x290 > [ 311.424327] kthread+0x19e/0x1c0 > [ 311.424330] ret_from_fork+0x32/0x40 > > [ 311.424334] The buggy address belongs to the object at > ffff88041fd610c0 > which belongs to the cache kmalloc-64 of size 64 > [ 311.424340] The buggy address is located 27 bytes inside of > 64-byte region [ffff88041fd610c0, ffff88041fd61100) > [ 311.424344] The buggy address belongs to the page: > [ 311.424348] page:ffffea00107f5840 count:1 mapcount:0 mapping: > (null) index:0x0 > [ 311.424353] flags: 0x17ffffc0000100(slab) > [ 311.424358] raw: 0017ffffc0000100 0000000000000000 0000000000000000 > 00000001802a002a > [ 311.424363] raw: dead000000000100 dead000000000200 ffff8804228036c0 > 0000000000000000 > [ 311.424366] page dumped because: kasan: bad access detected > > [ 311.424369] Memory state around the buggy address: > [ 311.424373] ffff88041fd60f80: 00 00 00 00 00 00 00 00 00 00 00 00 > 00 00 00 00 > [ 311.424377] ffff88041fd61000: fb fb fb fb fb fb fb fb fc fc fc fc > fb fb fb fb > [ 311.424381] >ffff88041fd61080: fb fb fb fb fc fc fc fc fb fb fb fb > fb fb fb fb > [ 311.424384] ^ > [ 311.424387] ffff88041fd61100: fc fc fc fc fb fb fb fb fb fb fb fb > fc fc fc fc > [ 311.424391] ffff88041fd61180: fb fb fb fb fb fb fb fb fc fc fc fc > fb fb fb fb > > Cc: stable@vger.kernel.org > Signed-off-by: Nick Desaulniers > --- > drivers/input/rmi4/rmi_driver.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c > index 4f2bb59..141ea22 100644 > --- a/drivers/input/rmi4/rmi_driver.c > +++ b/drivers/input/rmi4/rmi_driver.c > @@ -230,8 +230,10 @@ static irqreturn_t rmi_irq_fn(int irq, void *dev_id) > rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev, > "Failed to process interrupt request: %d\n", ret); > > - if (count) > + if (count) { > kfree(attn_data.data); > + attn_data.data = NULL; > + } > > if (!kfifo_is_empty(&drvdata->attn_fifo)) > return rmi_irq_fn(irq, dev_id); Ugh, this code needs reworking as we really do not want recursion in an interrupt handler. Anyway, this will suffice for stable; applied, thank you. -- Dmitry