Received: by 10.223.185.111 with SMTP id b44csp921363wrg; Fri, 9 Mar 2018 16:56:02 -0800 (PST) X-Google-Smtp-Source: AG47ELvTL7YiwanDDBPwkLDMEwyZ7b85BzBqZHdnrcgFQjLpxyHXFtu8lJoy3LTeonN+d997gRzk X-Received: by 2002:a17:902:4222:: with SMTP id g31-v6mr377485pld.335.1520643362114; Fri, 09 Mar 2018 16:56:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520643362; cv=none; d=google.com; s=arc-20160816; b=MxE8KEXCYGLqWu+ZSHZDlykCQZ2RlvpPiIwoIDoiz3groTj8e7UFvoGYcnWlC25lEh Ii6l95+0j7VB4sHH/E07umG/B0hhwdQzpa7AAK/Un5M8eWUpgOAAlRJqenNy0HIimsX4 THDxWubfbitBJPT7wH4NYx4rYuUlfnZQlooktFl08YZ2YXQV6WdA1+7uEauR0v+bllba Q/kWhjd9NQz/Gwm3rtRnNZtvGW1qnyQ1nHQ9pNS5RJSrNXy/LFZ1UdZln+qEH63pfau6 epcrkrbV1oGkn0uNHFDEQ41tv5JzwPuF70rM60b6kqgk1skEnOjuGWzl6j7TtYhmp6IQ fPoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:subject:cc:to :from:date:arc-authentication-results; bh=x13OgXZXXu0fqwqfSM+nGKmYXVStmO6fEbDqXIuRDlA=; b=BGThJ1wgw0a8GgfOenbzkU7A9cWJFHkzSUUPOFSAncjhWnATK3Bc+O2neJg9IdRjCr 8j8fpexggVxKL53keH+qXDDkK3dSUgvl+TYKBycDsdk5peu2Jmvf4AMfGkJJ3oIr4OjQ 6TlpLMJUGsElN8lo5ZnorjRGqY7tpZ4bVh854aoDLdx2WamF3+BqmjM6JdjiQllzuGag FEadlwt1blfniXYbVYNaQuf3kG/CnK40YPGPKrywrFTqiima6ZkVrJngjf2f4ZIIojDJ I0ATk3Jd/RllkNHqzt7IKoVLWlRyTwZNZFk7HXq4f1BVDE0Y7LZgPT53cBAckjt+JwBy itWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a74si1791981pfj.287.2018.03.09.16.55.47; Fri, 09 Mar 2018 16:56:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932835AbeCJAy5 (ORCPT + 99 others); Fri, 9 Mar 2018 19:54:57 -0500 Received: from 1.mo2.mail-out.ovh.net ([46.105.63.121]:54936 "EHLO 1.mo2.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932759AbeCJAy4 (ORCPT ); Fri, 9 Mar 2018 19:54:56 -0500 X-Greylist: delayed 8706 seconds by postgrey-1.27 at vger.kernel.org; Fri, 09 Mar 2018 19:54:56 EST Received: from player729.ha.ovh.net (unknown [10.109.120.19]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id D3D2711329A for ; Fri, 9 Mar 2018 23:29:48 +0100 (CET) Received: from heffalump.sk2.org (gw.sk2.org [88.186.243.14]) (Authenticated sender: steve@sk2.org) by player729.ha.ovh.net (Postfix) with ESMTPSA id 096C15E0090; Fri, 9 Mar 2018 23:29:38 +0100 (CET) Date: Fri, 9 Mar 2018 23:29:33 +0100 From: Stephen Kitt To: Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Hannes Reinecke Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Kernel Hardening Subject: VLA removal, device_handler and COMMAND_SIZE Message-ID: <20180309232933.14e39858@heffalump.sk2.org> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/ND1RoT20ph5rx/6uVsD0LuU"; protocol="application/pgp-signature" X-Ovh-Tracer-Id: 782500436982517069 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtfedrkeeigdduheelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Sig_/ND1RoT20ph5rx/6uVsD0LuU Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, I=E2=80=99ve been looking into removing some VLAs from device_handler drive= rs, prompted by https://lkml.org/lkml/2018/3/7/621 The uses in question here are quite straightforward, e.g. in drivers/scsi/device_handler/scsi_dh_alua.c: u8 cdb[COMMAND_SIZE(MAINTENANCE_IN)]; There=E2=80=99s no trivial way of keeping the compiler happy with -Wvla tho= ugh here, at least not while keeping the behaviour strictly identical. I=E2=80=99ve c= ome up with two approaches, and I=E2=80=99m curious whether they=E2=80=99re approp= riate or if there=E2=80=99s a better way... The first approach is to use MAX_COMMAND_SIZE instead; this wastes a few bytes on the stack here and there, and stays reasonably maintainable. The second approach might be symptomatic of a twisted mind, and involves replacing COMMAND_SIZE so that it can be calculated at compile time when the opcode is known: /* * SCSI command sizes are as follows, in bytes, for fixed size commands, per * group: 6, 10, 10, 12, 16, 12, 10, 10. The top three bits of an opcode * determine its group. * The size table is encoded into a 32-bit value by subtracting each value * from 16, resulting in a value of 1715488362 * (6 << 28 + 6 << 24 + 4 << 20 + 0 << 16 + 4 << 12 + 6 << 8 + 6 << 4 + 10). * Command group 3 is reserved and should never be used. */ #define COMMAND_SIZE(opcode) \ (16 - (15 & (1715488362 >> (4 * (((opcode) >> 5) & 7))))) This has the side-effect of making some of the call sites more complex, and the macro itself isn=E2=80=99t the most maintainer-friendly. It does mean w= e can drop BLK_SCSI_REQUEST from drivers/target/Kconfig so it=E2=80=99s not all bad... Both patches will follow in reply to this email, I=E2=80=99ll let more fami= liar developers judge which is appropriate (if any). Regards, Stephen --Sig_/ND1RoT20ph5rx/6uVsD0LuU Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEnPVX/hPLkMoq7x0ggNMC9Yhtg5wFAlqjCs0ACgkQgNMC9Yht g5zk6A//RgjRyD4aFvyZl/eCAy/q6gNM2ocvJzRHBsHKaNPlTEx5vEkjAZYHntoV tnRf/nmiNrq5OLzfH7IDig0/P6IAh9WZBQKyO5RSL/NDqSKny6+M5grxTN8+hLl6 D+ODmC8MOvQmtwIfu3zj/OGNCvZmEfqW//DAg/v6QgHKMQtwhxXRoh7BqOlMt/Qm f+27uE5BdPoOrXwJ7AcMBy4xHm7RvSpuUMUkOTpIEe4DvnqCMQK3wDjpvSLqJcv5 m7toKh3D5neVqL6jLKykWb1+4L0EQUokd4i0LCcp69evzT21MqwAyvHpLyBSS+EN AW9mX017A1OY/nraKEhbV84jlWh0LggMe9rzHoBqNLOEtJ7F3/7RBasnEIYQs3vj s03GFz3qc82X0gX9MF1e6SgkvpRlSHEexvph2mMC2bGw9qRnoU2iwOhptM4LzB1t D+YZ+XG8vOQ97TlT0BEIpuKsZCOJFcWW3rdl1kc4/s2F04daCdBWTVCYbPJZi767 uub1reBwy8U1LNr9ZhtS0LnghY+VGOzeeiZTMboIv0895ERgWbTR6M84xJcBoyOh Kb7mxjH1dG2kqdp0RJLrFY32rXZuswvO1Fwl+GfDKXy0Dx5XUxfLU1BY8zcaBly9 BNtHLwOx/F9UkQqTp5CbQvBNQuvAjOi8k/IQkdckph9H/DKBsgE= =b4fl -----END PGP SIGNATURE----- --Sig_/ND1RoT20ph5rx/6uVsD0LuU--