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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 8DA59C64E8A for ; Mon, 30 Nov 2020 13:45:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7C31206D8 for ; Mon, 30 Nov 2020 13:45:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alien8.de header.i=@alien8.de header.b="M9yS26lN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgK3Np3 (ORCPT ); Mon, 30 Nov 2020 08:45:29 -0500 Received: from mail.skyhub.de ([5.9.137.197]:40698 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725939AbgK3Np2 (ORCPT ); Mon, 30 Nov 2020 08:45:28 -0500 Received: from zn.tnic (p200300ec2f0c0400b0063e9f0046aa3d.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:400:b006:3e9f:46:aa3d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 1F9891EC04A9; Mon, 30 Nov 2020 14:44:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1606743887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=enMUDweG7jQb0semvEMxAkl78zQ8YKxuI5qRFWoLr/Y=; b=M9yS26lNcZtTToWA06fe1dksqSx0S4o09Hj+4I37mTaol2zb2O+x+0QJl4Ym7Y5v/hy9Qq GVIRe0FJWJ1OfO1Ousi+NNSuwXvUbIv2tVmBz0VIkyJ7Cmr+8dX9tw/F7TGHfTM4QjyWYA +RcLRhBsPB5h5hhJHyWWR//JFhcsFSE= Date: Mon, 30 Nov 2020 14:44:42 +0100 From: Borislav Petkov To: Masami Hiramatsu Cc: Andy Lutomirski , X86 ML , LKML Subject: Re: [RFC PATCH v0 00/19] x86/insn: Add an insn_decode() API Message-ID: <20201130134442.GB6019@zn.tnic> References: <20201124101952.7909-1-bp@alien8.de> <20201124174647.GI4009@zn.tnic> <20201129175005.7e07a9f799e888ffd5f4ed67@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201129175005.7e07a9f799e888ffd5f4ed67@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 29, 2020 at 05:50:05PM +0900, Masami Hiramatsu wrote: > Good point. I think we can return, e.g. -EFAULT if we failed in > get_next(). Then, we can read out next page, for example. Why -EFAULT? Running this size = 1; ret = insn_decode(&insn, b, size, INSN_MODE_64) i.e., buffer size is 1: ./arch/x86/tools/insn_sanity: Success: decoded and checked 10000 random instructions with 0 errors (seed:0x9994a137) insn buffer: 0x48 0xcf 0x48 0x83 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 0x90 supplied buf size: 15, ret 0 supplied buf size: 2, ret 0 supplied buf size: 3, ret 0 supplied buf size: 4, ret 0 insn_decode: entry insn_decode: will get_length insn_get_immediate: getting immediate insn_get_displacement: getting displacement insn_get_sib: getting sib insn_get_modrm: entry insn_get_opcode: entry insn_get_prefixes: entry, prefixes->got: 0 insn_get_prefixes: 1 insn_get_prefixes: REX insn_get_prefixes: VEX insn_get_prefixes: validate_next: 0 insn_get_prefixes: insn->next_byte: 0x7ffec297c3e1, insn->end_kaddr: 0x7ffec297c3e1 insn_get_prefixes: errored out supplied buf size: 1, ret -22 is caught in validate_next() where ->next_byte == ->end_kaddr. I'm thinking we should return EOF here, to denote that we're reached the end and then propagate that error up the callchain. We don't have "define EOF" in the kernel but we can designate one for the insn decoder, perhaps #define EOF -1 as stdio.h does: /* The value returned by fgetc and similar functions to indicate the end of the file. */ #define EOF (-1) Hmm, but then the callers would need to know EOF too so maybe EIO or something. In any case, it should be a value which callers should be able to use to get told that input buffer is truncated... Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette