From owner-freebsd-hackers@freebsd.org Tue Nov 3 10:00:08 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 E6283453707 for ; Tue, 3 Nov 2020 10:00:08 +0000 (UTC) (envelope-from xtouqh@hotmail.com) 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 4CQQJ83y22z4t3T for ; Tue, 3 Nov 2020 10:00:08 +0000 (UTC) (envelope-from xtouqh@hotmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id 85AE84533D6; Tue, 3 Nov 2020 10:00:08 +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 856BE4534CB for ; Tue, 3 Nov 2020 10:00:08 +0000 (UTC) (envelope-from xtouqh@hotmail.com) Received: from EUR06-VI1-obe.outbound.protection.outlook.com (mail-vi1eur06olkn2045.outbound.protection.outlook.com [40.92.17.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "GlobalSign Organization Validation CA - SHA256 - G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CQQJ714Krz4tDt for ; Tue, 3 Nov 2020 10:00:06 +0000 (UTC) (envelope-from xtouqh@hotmail.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DLBqHa5UFZMsQGmp5OR+SOoMPXopvgKF2q8Sk90c2KDi6SHss3hzvXgY6+ggozi7e+X7HuxmqxR2ICNNSUK6M0fzUc/amTlibqxyF6yCiWYRWP/H+qrhsG4evjBtcJE07UzrS6qwJC4QSrEUYCVa/P9nsDALROm2n+BLVMEIxfrAxcfmcdVbXZjSEtWid1EdREnOa9mo0XG+NvE2j166nayusRP6yVP/570jmCluk135IcPzqJ2bBYONKIOTTdPaZ1hAmBEmbGb+En1cwIFFFOEhLQip8LtW3hVkM130u8LjNC35hpnwpT2sTKuE3GQUfRA9whOMXExd9pIBWTvbsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5roKBYwYwa2BuxdLt3GhXKkiNHMB5vbWJsRslitLSeY=; b=dD9tI5Va20l/g73oJ5L64ZiaT2SGfy5gDbJmZnxbtNMDqbtEwnWm93jYDdz4aJ5ZLnD9As39gLzU2WeumHAvRF85cl/XqiDTsSAPQbycSAuc8uaHy0+21FaWH3pguDTkn+XzMZ+jzPUpR1oAxeNB+ssko6tfFmhXlQQOdaQ7UtitLlaLTvsGq+yFGkeBHlSPdV7FkK+3MDK8sQVgluz0PRQqZHMartc9rhozMeC61Tjiq5pN7oo1jr/RdIwtDQBg+NXQRj8PQfr9JvqXSxB6ugCEKvJCOpYTvhzak3cqLMf+kJZFC0AdtKBAtSIs6W/kVXaCGx0T2g58LCjonN1HNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5roKBYwYwa2BuxdLt3GhXKkiNHMB5vbWJsRslitLSeY=; b=qj07wZ+uZTD8FNYcqux0dtSwjBwH6aJh0VWf6BagVEK991JE0N709VIO/V5/NcqTXdzJv24iS/EPkVjKqbkr21khztY3J6F1vmot9JlbZvQov2UPhFRUzTnkwu7Rhhfl6cPGBma9hfP1GUwGYeuDwSCVXVuXrQZeb3/hj8Nx/Eeb0kTrPxEFH11bYM3L8KVwqwOKvHnFc/Ps1JTNerljjoUj4W2Gq/kWSV4tOBcqfX3EJ+DFLI22w6b9roFjjNWY36Q9K9cVph3T+tZeaMZRgO0jxcF6iPR+kjl/janAmermyNVlsB9HysT83fMZn7FdSEO2SwRJJO5caa9EEVgOxw== Received: from VI1EUR06FT022.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc37::4d) by VI1EUR06HT106.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc37::285) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3520.15; Tue, 3 Nov 2020 10:00:03 +0000 Received: from AM0PR06MB3986.eurprd06.prod.outlook.com (2a01:111:e400:fc37::43) by VI1EUR06FT022.mail.protection.outlook.com (2a01:111:e400:fc37::220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3520.15 via Frontend Transport; Tue, 3 Nov 2020 10:00:03 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:848AB1F2FF93C57B631742E395C7A3072F9E45EA6CDF27C77C503CF95BB2DC05; UpperCasedChecksum:D726C02C7A6661E5D0D80727392AC9D95E58DDF859B881BB3DDE00C144470158; SizeAsReceived:8731; Count:47 Received: from AM0PR06MB3986.eurprd06.prod.outlook.com ([fe80::759a:af46:6f2:8fb8]) by AM0PR06MB3986.eurprd06.prod.outlook.com ([fe80::759a:af46:6f2:8fb8%7]) with mapi id 15.20.3499.032; Tue, 3 Nov 2020 10:00:03 +0000 Subject: Re: KASSERT(val != 0) not triggering in linux_errno.c reading outside of array To: Hans Petter Selasky , hackers@freebsd.org References: <77d2eef0-9cc8-aa39-6d28-a7fb41e233ac@selasky.org> From: xtouqh@hotmail.com Message-ID: Date: Tue, 3 Nov 2020 13:00:02 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 In-Reply-To: <77d2eef0-9cc8-aa39-6d28-a7fb41e233ac@selasky.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TMN: [U7R9O91sBpedanvsLEXPfCVv3Nvy+gT2] X-ClientProxiedBy: FR2P281CA0014.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::24) To AM0PR06MB3986.eurprd06.prod.outlook.com (2603:10a6:208:b6::28) X-Microsoft-Original-Message-ID: <8d0572ce-cbbe-e777-0ee3-50c80fe54d29@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.6] (91.240.124.157) by FR2P281CA0014.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.10 via Frontend Transport; Tue, 3 Nov 2020 10:00:03 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 48bea9d5-77d0-4734-540e-08d87fdf3c0c X-MS-TrafficTypeDiagnostic: VI1EUR06HT106: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E+bD45JtYPvjQ7yRV55n/O3vzIDYRZm2Il46dP86n8bnmQnZ6d3YIt95OjQz6A83hjT4WzWtyy8S3S1ZI1c/PS+LoSQxRkwzmkuRdYoQBlCpit9WRhvF8o9qBL+RhTuOzWISioJfUARWUHKa4GsKeItKUewwXAn+CQ+n5DAuUbLx9W/LeINzfiXhS6xAAD+3/5orJDHOoSukLvQqddaeyU8lsS+HeHEk+Ff03XuFqyE4wQQ7qzcA5gWIOlGql6Is X-MS-Exchange-AntiSpam-MessageData: Pn8GFBjhoSibztwiHkcaPg9PcCJOAUAX9RImigc7iRRd62dMtWoayHR2p0zeCN8FEEs/SW4NGMP+jfYJNs1gHaZu078mJ6gbyLd+6EDSJtGxI5ZOMZBwkE85Pb2ubt0itvptRcGDMA6Abw/i8O2fMA== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48bea9d5-77d0-4734-540e-08d87fdf3c0c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 10:00:03.6949 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VI1EUR06FT022.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1EUR06HT106 X-Rspamd-Queue-Id: 4CQQJ714Krz4tDt X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=hotmail.com header.s=selector1 header.b=qj07wZ+u; dmarc=pass (policy=none) header.from=hotmail.com; spf=pass (mx1.freebsd.org: domain of xtouqh@hotmail.com designates 40.92.17.45 as permitted sender) smtp.mailfrom=xtouqh@hotmail.com X-Spamd-Result: default: False [-2.56 / 15.00]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[hotmail.com]; R_SPF_ALLOW(-0.20)[+ip4:40.92.0.0/15]; DKIM_TRACE(0.00)[hotmail.com:+]; SUBJECT_HAS_EXCLAIM(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-1.002]; DMARC_POLICY_ALLOW(-0.50)[hotmail.com,none]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[hotmail.com]; ASN(0.00)[asn:8075, ipnet:40.80.0.0/12, country:US]; FORGED_MUA_THUNDERBIRD_MSGID_UNKNOWN(2.50)[]; ARC_ALLOW(-1.00)[microsoft.com:s=arcselector9901:i=1]; NEURAL_HAM_MEDIUM(-1.03)[-1.031]; R_DKIM_ALLOW(-0.20)[hotmail.com:s=selector1]; RCVD_COUNT_FIVE(0.00)[5]; DWL_DNSWL_NONE(0.00)[hotmail.com:dkim]; NEURAL_HAM_LONG(-1.03)[-1.029]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_NO_DN(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[40.92.17.45:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[40.92.17.45:from]; 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 10:00:09 -0000 Hans Petter Selasky wrote: > 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? Yes, using amd64 GENERIC on -CURRENT, and that function itself is ifdef'ed INVARIANTS, so if it's executed, INVARIANTS are there when building the module and KASSERT() is not no-op. Though even without KASSERT(), simple if() is still not doing what I expect, so there must be something I'm missing.