Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3558063pxu; Mon, 30 Nov 2020 05:50:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxddd4ct/UhFZpBe7Zt+3RdgpVzDtB48ssW8cVp126k0I8Ii86HHm8fINvbNkM1sot5vcsV X-Received: by 2002:a17:906:710b:: with SMTP id x11mr14678830ejj.433.1606744234973; Mon, 30 Nov 2020 05:50:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606744234; cv=none; d=google.com; s=arc-20160816; b=SftPE2A+dkqkMQDr4n3UcZPzwzqc5wwzHy0UzBJZ0PmjklI/4di6tIQoeDEu2JlxNz l8Bc3re/B0PaeK+6W5sPA9lbhdwO0vZael2Wz8eWnjeejKr+frHjtaQJVvL1ttUYZZ9p 5ay1I2bFEf+SAx+sTGboy1WzLoExWfqM+nHHxr+2DlOGYZJkip+i63HnIXudpvZsqVkv n+Ur0j+9ogol5xC06tBqbiUNMRHHRk5JLU+KDpJjnMF04JNzWA+eBxD1tSxtZW5C8qQc Elz2zKC83oi50yMTPePFL8oGfAeLvoBAlzii4ylsvvvG3XhB3TXmEm5HzeNY4KHzZi6D NDUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=enMUDweG7jQb0semvEMxAkl78zQ8YKxuI5qRFWoLr/Y=; b=DQ0irNQ3Jt03FPBfPWT6X7hZ3rLdXKr2GSTmGXcvaA6bgZ7xVnHSmloghTToThIUeG +E7v6dMY+HvRtHwzqQQmFwelwsU5Cv4WxBvZ+rjhUq9CAeHF06WViXeqIxPmW75TLRWx aON/1U+66ffGPIHnIt2okC11Yt/C3J19NKY5sIvSOh3wsqSKnb9ByzbfoduTgPAnLYdj gqM1nVNLSNXoNV0+H03wQ8H4xGHjYNMQXjN0tDArTp2JS0vRbnOS0gFwM5bC5qlgUELz GY9XiSKwo3O1bux/SBNgGbiXPldFp3SICspzg9RVxVtc/cOy0NDB121Cm1Opa9P5lWUP XsSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=M9yS26lN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si11606167eje.368.2020.11.30.05.50.11; Mon, 30 Nov 2020 05:50:34 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=M9yS26lN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726289AbgK3Np2 (ORCPT + 99 others); Mon, 30 Nov 2020 08:45:28 -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