From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B477EC4332F for ; Sat, 17 Dec 2022 09:50:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:CC:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1WyVHxr4/Tpw2Tdop3qDBK/l+BeudAzf2D7XGkx+gUg=; b=z0YH2BBH8C0Dib eLC/V7jqZB6JvA0QD1Zwbvs9vbIjhXGXSSZZ3XYJ8IufkcaBdr1K8juuukwHyjJ+Hr3zlI8WZjKxK VsEyj9VO9nVkZEudOHG8SLNDF0Moqeq4E513OHXg7+wswSqAB3H5C7GOf8J4dug5EJ2vl6nr3n6An hyPAniUPvAJKYSd+aBtUNei5sPmfXbomf8b6HE1V0MG4R6w4+jbG+MsJ3jXVaWwc6w/pt35e58K/B sY0PQF57QV0yEoQDC8eJ59pBj1wo6fOJpyLz8zu9NoBBbq5MYARO/ksJIm34CaZSG7lhXG+dElkhp CcU2lgM4ufc3tNceJgew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p6Toe-007nM5-HX; Sat, 17 Dec 2022 09:49:12 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p6ToT-007nHG-50 for linux-arm-kernel@lists.infradead.org; Sat, 17 Dec 2022 09:49:06 +0000 Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NZ1Kb0XJfzJpPM; Sat, 17 Dec 2022 17:45:07 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Sat, 17 Dec 2022 17:48:47 +0800 Message-ID: <23c0aa08-1dc0-31df-90d2-3231c78768d1@huawei.com> Date: Sat, 17 Dec 2022 17:48:47 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] arm64: fix a concurrency issue in emulation_proc_handler() Content-Language: en-US To: Mark Rutland CC: , , , , , References: <20221209105556.47621-1-ruanjinjie@huawei.com> From: Ruan Jinjie In-Reply-To: X-Originating-IP: [10.67.109.254] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221217_014905_194319_8719BADA X-CRM114-Status: GOOD ( 18.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2022/12/9 19:09, Mark Rutland wrote: > On Fri, Dec 09, 2022 at 06:55:56PM +0800, ruanjinjie wrote: >> In emulation_proc_handler(), read and write operations are performed on >> insn->current_mode. In the concurrency scenario, mutex only protects >> writing insn->current_mode, and not protects the read. Suppose there are >> two concurrent tasks, task1 updates insn->current_mode to INSN_EMULATE >> in the critical section, the prev_mode of task2 is still the old data >> INSN_UNDEF of insn->current_mode. As a result, two tasks call >> update_insn_emulation_mode twice with prev_mode = INSN_UNDEF and >> current_mode = INSN_EMULATE, then call register_emulation_hooks twice, >> resulting in a list_add double problem. >> >> Call trace: >> __list_add_valid+0xd8/0xe4 >> register_undef_hook+0x94/0x13c >> update_insn_emulation_mode+0xd0/0x12c >> emulation_proc_handler+0xd8/0xf4 >> proc_sys_call_handler+0x140/0x250 >> proc_sys_write+0x1c/0x2c >> new_sync_write+0xec/0x18c >> vfs_write+0x214/0x2ac >> ksys_write+0x70/0xfc >> __arm64_sys_write+0x24/0x30 >> el0_svc_common.constprop.0+0x7c/0x1bc >> do_el0_svc+0x2c/0x94 >> el0_svc+0x20/0x30 >> el0_sync_handler+0xb0/0xb4 >> el0_sync+0x160/0x180 > > The version queued in the arm64 for-next/core branch no longer has the list > manipulation, but we do need to fix this for stable, and there is a remaining > race on reading insn->current_mode in emulation_proc_handler(). Hi Mark, Should I send this patch to linux-stable? > >> Fixes: af483947d472 ("arm64: fix oops in concurrently setting insn_emulation sysctls") >> Signed-off-by: ruanjinjie >> --- >> arch/arm64/kernel/armv8_deprecated.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c >> index fb0e7c7b2e20..d33e5d9e6990 100644 >> --- a/arch/arm64/kernel/armv8_deprecated.c >> +++ b/arch/arm64/kernel/armv8_deprecated.c >> @@ -208,10 +208,12 @@ static int emulation_proc_handler(struct ctl_table *table, int write, >> loff_t *ppos) >> { >> int ret = 0; >> - struct insn_emulation *insn = container_of(table->data, struct insn_emulation, current_mode); >> - enum insn_emulation_mode prev_mode = insn->current_mode; >> + struct insn_emulation *insn; >> + enum insn_emulation_mode prev_mode; >> >> mutex_lock(&insn_emulation_mutex); >> + insn = container_of(table->data, struct insn_emulation, current_mode); >> + prev_mode = insn->current_mode; >> ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); > > We don't strictly need to move the container_of(), but it makes no odds either > way, and this looks good to me: > > Acked-by: Mark Rutland > > Mark. > >> >> if (ret || !write || prev_mode == insn->current_mode) >> -- >> 2.25.1 >> > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel