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 X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A07F0C2D0A8 for ; Wed, 23 Sep 2020 08:50:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22150206BE for ; Wed, 23 Sep 2020 08:50:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pQZd6PoC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22150206BE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ghRQosMxRLMdbiRVNpshtXVaWUfcUrHm4KwrLVndsOc=; b=pQZd6PoCxmNzBdpfzpuZ9uf6A E0Z3D0e/+zxlVZfjHaLE0ZapcZNXcQWmRSoOFxtR7Jp3jAEIH6puC9CHpKXM1ADiV+vNu2RtersIr 6QSaUPlafQnhuTsBt+gC7qiYrLbFTYq0K49ILhFp9H7pSSrvv60Tny1DwkICxDs/bVrtcL1hBAdme X2z4Xj6lSf44uJ7UcOylAuflEIuPLr4dCZzIMFZ8DA07OIJGeg0/VPZ0kFMrkQGNDVjLGbLqXqZu5 A/1K1kDUErdvT/A0G3804I/hFNc4XH46nIFHMzR7MMJzAJ7efOb9bigWQdjob/phQ8fL0V4HMEI65 DaoWeWwVg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL0T6-0000pu-Nv; Wed, 23 Sep 2020 08:49:41 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kL0T1-0000nf-6o for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 08:49:36 +0000 Received: from gaia (unknown [31.124.44.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2694B206BE; Wed, 23 Sep 2020 08:49:32 +0000 (UTC) Date: Wed, 23 Sep 2020 09:49:30 +0100 From: Catalin Marinas To: Amit Kachhap Subject: Re: [PATCH 6/6] kselftest/arm64: Check mte tagged user address in kernel Message-ID: <20200923084930.GB13434@gaia> References: <20200901092719.9918-1-amit.kachhap@arm.com> <20200901092719.9918-7-amit.kachhap@arm.com> <20200922104123.GF15643@gaia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200923_044935_393185_691FDEE5 X-CRM114-Status: GOOD ( 21.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shuah Khan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org 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 Wed, Sep 23, 2020 at 12:36:59PM +0530, Amit Kachhap wrote: > On 9/22/20 4:11 PM, Catalin Marinas wrote: > > On Tue, Sep 01, 2020 at 02:57:19PM +0530, Amit Daniel Kachhap wrote: > > > +static int check_usermem_access_fault(int mem_type, int mode, int mapping) > > > +{ > > > + int fd, ret, i, err; > > > + char val = 'A'; > > > + size_t len, read_len; > > > + void *ptr, *ptr_next; > > > + bool fault; > > > + > > > + len = 2 * page_sz; > > > + err = KSFT_FAIL; > > > + /* > > > + * Accessing user memory in kernel with invalid tag should fault in sync > > > + * mode but may not fault in async mode as per the implemented MTE > > > + * support in Arm64 kernel. > > > + */ > > > + if (mode == MTE_ASYNC_ERR) > > > + fault = false; > > > + else > > > + fault = true; > > > + mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG); > > > + fd = create_temp_file(); > > > + if (fd == -1) > > > + return KSFT_FAIL; > > > + for (i = 0; i < len; i++) > > > + write(fd, &val, sizeof(val)); > > > + lseek(fd, 0, 0); > > > + ptr = mte_allocate_memory(len, mem_type, mapping, true); > > > + if (check_allocated_memory(ptr, len, mem_type, true) != KSFT_PASS) { > > > + close(fd); > > > + return KSFT_FAIL; > > > + } > > > + mte_initialize_current_context(mode, (uintptr_t)ptr, len); > > > + /* Copy from file into buffer with valid tag */ > > > + read_len = read(fd, ptr, len); > > > + ret = errno; > > > > My reading of the man page is that errno is set only if read() returns > > -1. > > Yes. The checks should be optimized here. It's not about optimisation but correctness. The errno man page states that errno is only relevant if the syscall returns -1. So it may potentially hold a stale value (e.g. EFAULT) in case of read() success but the check below fails anyway: > > > + mte_wait_after_trig(); > > > + if ((cur_mte_cxt.fault_valid == true) || ret == EFAULT || read_len < len) > > > + goto usermem_acc_err; -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel