From owner-freebsd-hackers@freebsd.org Tue Nov 3 11:45:41 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 BA99245584F for ; Tue, 3 Nov 2020 11:45:41 +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 4CQSdx3Pc5z3Wh8 for ; Tue, 3 Nov 2020 11:45:41 +0000 (UTC) (envelope-from xtouqh@hotmail.com) Received: by mailman.nyi.freebsd.org (Postfix) id 72E7E45584E; Tue, 3 Nov 2020 11:45:41 +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 716D54557CE for ; Tue, 3 Nov 2020 11:45:41 +0000 (UTC) (envelope-from xtouqh@hotmail.com) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2073.outbound.protection.outlook.com [40.92.89.73]) (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 4CQSdw1RSvz3WMm for ; Tue, 3 Nov 2020 11:45:39 +0000 (UTC) (envelope-from xtouqh@hotmail.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A/ywJ2BTbOsUHKJcqjphEDH+zdFYvAFRlsQSt7LaaFmQbB8DFe2tr1WGRdbzrlONy0R3M98JYkoUwwkyBT3tKf9696FteGJoazhYfmY9uVD3seZ1zTleMA1aC4tFjXGYPHkFL8W/H2FzeLXiX3Wd94WNwcwbugnabP3P7J12v1blhvNkUWOfTXTN4NP6khEIrUyQp1bpqbQZNcL9PW4rQi1IawlAZvfLHtOcIYrkvgmv6ar+fP3QNBzcZiz2Y6Y54IssSY8mEL98z+bD0TtgGLHIu7v9upX9jpMSGKAiPYtENbUidvYKuMrXJa8gf6v6T1yPA1Eam2h4Fxf5kG2gMQ== 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=oa4OjwCU7ikz4HK+gkgaWaHCDkCmDzJqaFIjloN09jQ=; b=H15b+edCoR+ofir5WZJfnRcrQbtg7TQK3+Qlkm67PybPBEwVZm2EJkV+8SzceCerDTJry1CXGmB54mLgsMXMFOJQo9sMyOndey0dqaVkEHYmfSQ5SQB2IMy6qhpxT0KqJjYgDIA3zTVVBNBd6NfMt5XG1V61/emmaep2eXC6kV197ZQdWE30wDvzPljQHC0VorL5c0kcRx1R+BPZ7mvHp29j6hd82XiLJE131dNO2y5xPVQ2PJYp3gmPEYwFQPYqF/fveut1NQvpfbR7N5i5SJ6+NyEAVFvUn+brYpZZJtzHoRHpTrWJibMbU/6T+9HimB294bEYUlQA9Te8QCm6Ng== 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=oa4OjwCU7ikz4HK+gkgaWaHCDkCmDzJqaFIjloN09jQ=; b=UbHQiwB5h7O7V1vTcYS+akzZ6pWs+BmIwMD1KjCUhakrGWTtKM6iVewmKUfr4wK2K1nHxu2xOWQKtR2QMQDdYIuSid6kSyNEPIzGbMFEipwNrAmbBS+LWIFFLwI0f5FC2pqIil29dPKPybjsVgDMh+dXe8Qiln6oZu4fPPOb8DZVAEjo5k9FB4qk1lRTcHsL5Iv4UUtN2fB3kcr7orMELh6LjBZ92MWdTw0HeRMX5gaG6RiTSCd59+J+9pNocZEN1M5x4i1Nkv7Rk9NBH/8GDKnueUdr7RlTV+ZcQlNkIIu4ocNQKyuNxIHDnuO7z4lqxyE1e59u/ifzmrOefmSA3w== Received: from DB8EUR05FT049.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::43) by DB8EUR05HT126.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc0f::414) 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 11:45:37 +0000 Received: from AM0PR06MB3986.eurprd06.prod.outlook.com (2a01:111:e400:fc0f::50) by DB8EUR05FT049.mail.protection.outlook.com (2a01:111:e400:fc0f::453) 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 11:45:37 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:E5D0965E4E5FABBA8806623986F90972824A3B5446350A2765BBEC0F1490B74F; UpperCasedChecksum:850E82D881C56A1393B31F7A38F5353DCA5132F6F2B2A1779FFEDF9660C2D193; SizeAsReceived:9038; Count:48 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 11:45:37 +0000 Subject: Re: KASSERT(val != 0) not triggering in linux_errno.c reading outside of array To: Konstantin Belousov Cc: Hans Petter Selasky , hackers@freebsd.org References: <77d2eef0-9cc8-aa39-6d28-a7fb41e233ac@selasky.org> <20201103111613.GP2654@kib.kiev.ua> From: xtouqh@hotmail.com Message-ID: Date: Tue, 3 Nov 2020 14:45:36 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 In-Reply-To: <20201103111613.GP2654@kib.kiev.ua> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TMN: [qwCrWIv4h9bMqP9PMZXUyf0aWPL7x9Ei] X-ClientProxiedBy: AM0PR04CA0069.eurprd04.prod.outlook.com (2603:10a6:208:1::46) To AM0PR06MB3986.eurprd06.prod.outlook.com (2603:10a6:208:b6::28) X-Microsoft-Original-Message-ID: <3e5a904c-5cd1-1657-1e2f-d1fd66a36f6b@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.6] (91.240.124.157) by AM0PR04CA0069.eurprd04.prod.outlook.com (2603:10a6:208:1::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.19 via Frontend Transport; Tue, 3 Nov 2020 11:45:36 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 7f6db867-2ede-496c-a017-08d87fedfb53 X-MS-TrafficTypeDiagnostic: DB8EUR05HT126: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AXFleqQQRxYZ6KEkAC5dz1QSqinTKGfIsnogf58kcehTnzfeRh30BVBb6TdT45uNXpDQT/35xlleTcYRf85WzDxnMQj1rYfKgEqrJaPFsPjjHVBKdjK4L/XaevnFqTH0HriwFLe9iagcvw6Ni+HxcVc36FHxfpAFQnldg8C5/dHxaXNo9DbXQkdJyRPkqJNG36pL6mMTc1pGsmHfHCQk8Q== X-MS-Exchange-AntiSpam-MessageData: UMKcD1bbM3RQFsGvNYLRcjOkgC7qAxreyzJ5dRC9BW83FI69JZcOul1xpLuCjXgjx7zu/0Pu63SC+Ns52DyrOhcIoYZb2UBy7Br0/dMHy70AaXoNSAh9MjZRjIWJll4+RgycaSs1rP6bLQ3ZTZR2rg== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f6db867-2ede-496c-a017-08d87fedfb53 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2020 11:45:37.5922 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR05FT049.eop-eur05.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: DB8EUR05HT126 X-Rspamd-Queue-Id: 4CQSdw1RSvz3WMm X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=hotmail.com header.s=selector1 header.b=UbHQiwB5; dmarc=pass (policy=none) header.from=hotmail.com; spf=pass (mx1.freebsd.org: domain of xtouqh@hotmail.com designates 40.92.89.73 as permitted sender) smtp.mailfrom=xtouqh@hotmail.com X-Spamd-Result: default: False [-2.36 / 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)[]; DMARC_POLICY_ALLOW(-0.50)[hotmail.com,none]; NEURAL_HAM_SHORT(-0.80)[-0.804]; FREEMAIL_TO(0.00)[gmail.com]; 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]; DWL_DNSWL_NONE(0.00)[hotmail.com:dkim]; NEURAL_HAM_MEDIUM(-1.04)[-1.041]; R_DKIM_ALLOW(-0.20)[hotmail.com:s=selector1]; RCVD_COUNT_FIVE(0.00)[5]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_HAM_LONG(-1.01)[-1.013]; 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.89.73:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[40.92.89.73: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 11:45:41 -0000 Konstantin Belousov wrote: > On Tue, Nov 03, 2020 at 01:17:51PM +0300, xtouqh@hotmail.com wrote: >> Hans Petter Selasky wrote: >>> Hi, >>> >>> Should: >>> >>>         for (i = 1; i < sizeof(linux_errtbl); i++) { >>> >>> Be: >>> >>>         for (i = 1; i < sizeof(linux_errtbl)/sizeof(linux_errtbl[0]); >>> i++) { >>> >>> >>> Or: >>> >>>         for (i = 1; i < (int)nitems(linux_errtbl); i++) { >> >> That's right, and I added the same comment in the review. My question is >> different though -- with the issue present, KASSERT() should have triggered >> (there are 0 values with incorrect indexes, added printf() confirms that) >> exposing the bug, but it does not -- WHY? -- I just want to understand >> what's going on. > > I think this is a poster child for the current undefined behaviour treatment > by compilers. You are accessing beyond array last element, and compiler can > prove it, so it allowed to do anything. Makes sense, thank you. Just for the record, if I compile userland test case with -O2, it behaves the same; previously I was building without explicitly specifying optimization level, and it did "work".