Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1882199ybt; Mon, 15 Jun 2020 11:51:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu/tvETuOCxEDeU+wwoFLzYeMeEW5bdixM2CvACqC7XHG1iwL8rMd+O5o7IfCsR/FbnNNp X-Received: by 2002:a17:906:454b:: with SMTP id s11mr28134719ejq.546.1592247102133; Mon, 15 Jun 2020 11:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592247102; cv=none; d=google.com; s=arc-20160816; b=vLcjKOTHaJez6INZXvRvYfi9pVG2Aj2aNdezUwLygOzeMcjw0mgr5olqtANZqHgUvM WVbPmVtUVARCPRL+DxYG54IJ1exHwfN4wF4L+fEol4IIPqnyS1+uULK/aQPQBUHsMcQB 27QjIocGSlQ14BU3RprfWdPQt6H2ShLufA/hW8hghB49fRyFBews3bWh3PYFPb1xiXll Z5v0OGEZY+XOxgBLZe+3B0ZsKKS9404r1HMZH05hfnIY5h9yUWGzbUxD0dVYufq2E83C s9mAeu9gD1zICN43w3+heoSM09FRyJY93ldB0JFTwaeyAFm83/P6hdGCpz7Pvd9u1aRw sccw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=z30H0Qxf7KSPQ6BN5/irrwQjH65QOzZKJjP0gLp4z7g=; b=yWoEDTOh9tbU34APtFjqrn2LBQi5bTKf1xOfaAj7O9PSs/XdYFk7VZ//ifSojWXBjZ dU/wBoD8bY4zzj1kXPmB12nevy0VJivvlr6FbdC71RO6u0ZPZuwzDT5evfZXMjH/G+kB 9Mc2eDlO5AIWybdtxDOU5MWDmhJhZyTCycOyAEs09GO8eQs4Cn1If/b1VWpDS6uGA9OP dTKIui3DJLpdVCePQpe/q1Krr1A3Yw5zw8CcH/Yhnuu5eck2llV1OJvIScpQmbClYYOS qstwJ5kQKx9R5+a7EDo0rlT3f0lGMToqvftd6BiZuaTBq0s+HdKg5Duw4D16eBFLUGrP qGBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gdHCBuPr; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si9524575ede.41.2020.06.15.11.51.18; Mon, 15 Jun 2020 11:51:42 -0700 (PDT) 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=@chromium.org header.s=google header.b=gdHCBuPr; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731397AbgFOSr0 (ORCPT + 99 others); Mon, 15 Jun 2020 14:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731332AbgFOSrY (ORCPT ); Mon, 15 Jun 2020 14:47:24 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C39DCC061A0E for ; Mon, 15 Jun 2020 11:47:23 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id k2so216087pjs.2 for ; Mon, 15 Jun 2020 11:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=z30H0Qxf7KSPQ6BN5/irrwQjH65QOzZKJjP0gLp4z7g=; b=gdHCBuPrKnl/TRBfkFZubK5Uo5+n8gz7oaaq3rFP6EfkFPpcYITIG5o0tcbfMe2V4K D9W3BIw1eqKbke/hnOSRgUBuvSG3DZLMUHhiJ55Zf6pzdDMAzewIxvFV9Wo+WHTEPc0q RzhapmD6JJ+dz1WI/eagPudg6hmkl/UgIMyzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=z30H0Qxf7KSPQ6BN5/irrwQjH65QOzZKJjP0gLp4z7g=; b=ads2MiKcgQ9ii+mUjNgGYePblwHeSMCoQoxA13sqADif87ksUtaihG+nls3ia2pXQM iiw21ucLj+dIHuEsY1ucXooJmm8uQ8HkPcfjG85TRvv68Az1dpbmKXCneHbJFqT5/Zzx 0TbVrgGTRxWZKdKOLSzifvKkJsseVCOtdZ9UABN4n5YjpBDUngQiQpc/l0wB68c424W5 vOnQdaj/hvfB/17PI4lyJ6SbGMAS2N0lllWt9gAph4uB/3BF6pB1koVIpSrmEi5IeDmn yfONe/SNqV1Qt8scHF2sK+ds8B/H7QMSGmtn2evL3zNhzauQvj8OsNLeKG3RULJGG/M/ Rj8g== X-Gm-Message-State: AOAM533PUuDDKt+wikmUwEUHkxhExZdGH1VRrFdX0dFuMDcEhhQTekOu TMIzluBcAEYmaeohf5I9MmRy8A== X-Received: by 2002:a17:90a:ea05:: with SMTP id w5mr672654pjy.37.1592246843289; Mon, 15 Jun 2020 11:47:23 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x77sm14582163pfc.4.2020.06.15.11.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 11:47:22 -0700 (PDT) Date: Mon, 15 Jun 2020 11:47:21 -0700 From: Kees Cook To: Nick Desaulniers Cc: Sami Tolvanen , James Morris , David Howells , "Eric W. Biederman" , KP Singh , Casey Schaufler , Thomas Cedeno , Anders Roxell , LKML , clang-built-linux Subject: Re: [PATCH] security: fix the key_permission LSM hook function type Message-ID: <202006151144.C9E5EA2C76@keescook> References: <20200615181232.119491-1-samitolvanen@google.com> <202006151113.7A2F638A7@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 15, 2020 at 11:23:44AM -0700, Nick Desaulniers wrote: > On Mon, Jun 15, 2020 at 11:21 AM Kees Cook wrote: > > > > On Mon, Jun 15, 2020 at 11:12:32AM -0700, Sami Tolvanen wrote: > > > Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than > > > a mask") changed the type of the key_permission callback functions, but > > > didn't change the type of the hook, which trips indirect call checking with > > > Control-Flow Integrity (CFI). This change fixes the issue by changing the > > > hook type to match the functions. > > > > > > Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") > > > Signed-off-by: Sami Tolvanen > > > > Thanks for fixing this! > > > > Acked-by: Kees Cook > > > > I wonder if there is any compiler option we can turn on to catch the > > implicit enum/int casting that would help for these kinds of things > > without absolutely exploding the build warnings. > > > > I see -Wenum-conversion, but that seems to be between enums, not between > > int. > > > > I see this, but it's external: > > https://noamlewis.wordpress.com/2017/10/05/type-safe-enums-in-c-using-a-clang-plugin/ > > Unfortunately, using a looser integral type is the typical workaround > for -Wenum-conversion warnings (which is on by default, GCC recently > added that flag, too). For warning on enum to int, the kernel would > probably blow up with warnings. I don't know of any such existing > warning flag. Yeah, I couldn't find anything either. The closest I could find to avoid one of the common classes of enum -> int conversion is the bitwise operations, which is covered by __attribute__((flag_enum)): https://clang.llvm.org/docs/AttributeReference.html#flag-enum Ah well. We'll let CFI find them. ;) -- Kees Cook