Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2296041pxb; Sun, 30 Jan 2022 11:06:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxx/XYtJFKfcBvLlk5EXZuFOhZeZz2tF6nQz77yTy9JRqPBhLB95ejnT2PjPYRj0Z5LICqf X-Received: by 2002:aa7:d816:: with SMTP id v22mr17333617edq.221.1643569572703; Sun, 30 Jan 2022 11:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643569572; cv=none; d=google.com; s=arc-20160816; b=oJTvsO5HSB+dgnPouEBsXrCYSN2plAzwtL94mfJthh+YuyWhzH3fDRlyQhGk3Gv+7N drfV3qktg/winjSMTcFiTyjp7K0zfvP0RJpvNVRD4BKLnp2FBxAPq5UpEn0CdsgM5zT+ HTBWlQwo9fGPaW3P/tqkc9Z/NaSMkGsf+Q8QkBszuE/QcamH8OGnELS/ZxSLQS74qXyj hAR08TzCHCzX6QvnLODXGt7zqnyy9E122ctt+ezfbeA+epSpsOOIiG1t1WlsPRfTuAEr Gg7C1B5SYdpBbpHMzPntrq+I002rXLavagEzzaIoZhu0vtH+e4PciR0loBHmGk7A0lpS aWNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=bziiqEycGZWVs2DHR0Io1c96Y0uk+eYvponbmUIAUWg=; b=dKXnhVlMwvEgDvUMPEMHqHMkDKEhlCThw7ValZMdaT34/DKgZeRkCA1RyOJY2CvSyM WbqUCtz/NeWIw6YzAYQWj0BDSvBUbXKO9CcbjJyP9Z1Z90dr3TRH4xHT4PfNA7UeFNTQ /uq++rVJjtaguXGWVm8ZI9wwKnXQfFsmYvrKsOWA/oElQgLK3OsUiGnMifDm12+dtdIy H/pRC4hZ4uBZu6Bmy2zI5JSz/SeKCwhsBd+tdJxqlItMO09a1HxKtS0JIpoh3i/7fuDc 64HJRWgvlSWO7OU5KNqugBBQ+CF6ZmG/qudlLmKu2Fn6HJdduFN1ebXaTAbGtBxkjHw/ DohQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si3632386ede.573.2022.01.30.11.05.48; Sun, 30 Jan 2022 11:06:12 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236045AbiA1JDa (ORCPT + 99 others); Fri, 28 Jan 2022 04:03:30 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]:31250 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235560AbiA1JD2 (ORCPT ); Fri, 28 Jan 2022 04:03:28 -0500 Received: from dggeme752-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JlWgb0MQpzbkCc; Fri, 28 Jan 2022 17:02:35 +0800 (CST) Received: from huawei.com (10.175.124.27) by dggeme752-chm.china.huawei.com (10.3.19.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.21; Fri, 28 Jan 2022 17:03:26 +0800 From: h00486469 To: , , , , CC: , Subject: [PATCH] arm64: fix slab-out-of-bounds in emulation_proc_handler when accessing concurrently Date: Fri, 28 Jan 2022 17:03:24 +0800 Message-ID: <20220128090324.2727688-1-hewenliang4@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggeme752-chm.china.huawei.com (10.3.19.98) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: hewenliang SAN reports an issue of slab-out-of-bounds in emulation_proc_handler when we try to read/write the interfaces in /proc/sys/abi concurrently. So we need to add emulation_proc_lock to protect table->data and insn from data corruption in emulation_proc_handler. The stack is follows: Call trace: dump_backtrace+0x0/0x310 show_stack+0x28/0x38 dump_stack+0xec/0x15c print_address_description+0x68/0x2d0 kasan_report+0x130/0x2f0 __asan_load4+0x88/0xb0 emulation_proc_handler+0x58/0x158 proc_sys_call_handler+0x1dc/0x228 proc_sys_read+0x44/0x58 __vfs_read+0xe0/0x320 vfs_read+0xbc/0x1c0 __arm64_sys_read+0x50/0x60 el0_svc_common+0xc8/0x2b8 el0_svc_handler+0xf8/0x160 el0_svc+0x10/0x218 Allocated by task 1: kasan_kmalloc+0xe0/0x190 kmem_cache_alloc_trace+0x18c/0x418 register_insn_emulation+0x4c/0x2b0 armv8_deprecated_init+0x40/0x108 do_one_initcall+0xb4/0x508 kernel_init_freeable+0x7d0/0x8e0 kernel_init+0x20/0x1a8 ret_from_fork+0x10/0x18 Mmeory state around the buggy address: >ffff8026dacf0b00: 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc fc Fixes: 587064b610c7 ("arm64: Add framework for legacy instruction emulation") Signed-off-by: hewenliang Signed-off-by: hejingxian Signed-off-by: fulin --- arch/arm64/kernel/armv8_deprecated.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index 6875a16b09d2..d2ac483b0dd8 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -59,6 +59,7 @@ struct insn_emulation { static LIST_HEAD(insn_emulation); static int nr_insn_emulated __initdata; static DEFINE_RAW_SPINLOCK(insn_emulation_lock); +static DEFINE_MUTEX(emulation_proc_lock); static void register_emulation_hooks(struct insn_emulation_ops *ops) { @@ -207,9 +208,12 @@ static int emulation_proc_handler(struct ctl_table *table, int write, loff_t *ppos) { int ret = 0; - struct insn_emulation *insn = (struct insn_emulation *) table->data; - enum insn_emulation_mode prev_mode = insn->current_mode; + struct insn_emulation *insn; + enum insn_emulation_mode prev_mode; + mutex_lock(&emulation_proc_lock); + insn = (struct insn_emulation *) table->data; + prev_mode = insn->current_mode; table->data = &insn->current_mode; ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); @@ -224,6 +228,7 @@ static int emulation_proc_handler(struct ctl_table *table, int write, } ret: table->data = insn; + mutex_unlock(&emulation_proc_lock); return ret; } -- 2.27.0