From owner-freebsd-hackers@freebsd.org Tue Nov 3 09:55:36 2020 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5C436453143 for ; Tue, 3 Nov 2020 09:55:36 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4CQQBw0W11z4sWJ for ; Tue, 3 Nov 2020 09:55:36 +0000 (UTC) (envelope-from hps@selasky.org) Received: by mailman.nyi.freebsd.org (Postfix) id 0FB74453387; Tue, 3 Nov 2020 09:55:36 +0000 (UTC) Delivered-To: hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0F8314531C0 for ; Tue, 3 Nov 2020 09:55:36 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CQQBt6VwTz4sT6 for ; Tue, 3 Nov 2020 09:55:34 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2020.home.selasky.org (unknown [178.17.145.105]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 4B1AB2600E0; Tue, 3 Nov 2020 10:55:27 +0100 (CET) Subject: Re: KASSERT(val != 0) not triggering in linux_errno.c reading outside of array To: xtouqh@hotmail.com, hackers@freebsd.org References: From: Hans Petter Selasky Message-ID: <77d2eef0-9cc8-aa39-6d28-a7fb41e233ac@selasky.org> Date: Tue, 3 Nov 2020 10:55:25 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4CQQBt6VwTz4sT6 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of hps@selasky.org designates 2a01:4f8:c17:6c4b::2 as permitted sender) smtp.mailfrom=hps@selasky.org X-Spamd-Result: default: False [-2.08 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+a:mail.turbocat.net:c]; MID_RHS_MATCH_FROM(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[selasky.org]; NEURAL_SPAM_SHORT(0.25)[0.246]; NEURAL_HAM_LONG(-1.01)[-1.009]; TO_MATCH_ENVRCPT_SOME(0.00)[]; SUBJECT_HAS_EXCLAIM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_MEDIUM(-1.02)[-1.019]; FREEMAIL_TO(0.00)[hotmail.com,freebsd.org]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:2a01:4f8::/29, country:DE]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[hackers] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Nov 2020 09:55:36 -0000 On 2020-11-03 10:46, xtouqh@hotmail.com wrote: > I'm looking at the current sys/compat/linux/linux_errno.c source, > specifically this function: > https://svnweb.freebsd.org/base/head/sys/compat/linux/linux_errno.c?revision=367132&view=markup#l24, > and noticed that sizeof() usage there seems to be bogus as I mentioned > in https://reviews.freebsd.org/D26974#inline-168811. > > What I'm wondering about is why KASSERT() is not triggering there -- I > have added the following printf() right below KASSERT() showing that we > indeed read outside of the array, and some of the linux_errtbl[i] values > are 0: > > printf("%s:linux_errtbl[%d]=%d\n", __func__, i, linux_errtbl[i]); > > But, if I add the following check before printf(), it seems to be never > true: > > if (linux_errtbl[i] == 0) >     printf("%s:linux_errtbl[%d]=%d\n", __func__, i, linux_errtbl[i]); > > So how come printed values are 0, but KASSERT(value != 0) and if (value > == 0) are never true?  I tried to reproduce this in simple userland test > case, but the check seems to be working correctly there (though still > reading outside of array if using sizeof() for final index).  What am I > missing here? Did you enable INVARIANTS when compiling the kernel? --HPS