Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1865555ybt; Mon, 15 Jun 2020 11:23:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKetIDqB82CQXLXs7ZoQxcGW9knsmht6tc2euXfWV81NI13EUtHqzcTEPqE/5lGRmubCc0 X-Received: by 2002:a17:906:fb9b:: with SMTP id lr27mr13975948ejb.405.1592245417354; Mon, 15 Jun 2020 11:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592245417; cv=none; d=google.com; s=arc-20160816; b=bRHvDPKJS7RfyJrvhUwG5fdAQ70+CzIpG+3APBgWQErNeh7Fi1Q+kz2dHLc/yJYItV AQTTACaYC/WnOh2U/699OlAQsgxvN1i9LCc6BUJlQE0jaJg2XFn1u1tS6kSDavQ4W3S8 tkqbcLEqthyz+vsNwNRvUDf3i5/13TmvlZeLG2QEfivY2KcLLPJGUSsZoEGcO4/Ou/aH vOGseW3isB22oMB9AmlGAKJy4MsZ42ag78Oh718cy6C1a3+qSeVjLrdXSm1+resriysg QmluX8Q/dsGL700P3FyeTc85lSPBG9LT3LW1b2HrCB7fZ7hsMG2Uu6wiak6/Q9TEjJy2 pGJw== 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=LemJIWusSKTs9kB/F9oxsCC3XddFJYsF1dwWH4aB1F4=; b=cP6ktSm1MDw2DvJtnPw+ZRybK/+cREjduECsCRQihEX0KaOdpc9IkjWDFPd5E86p9T TdYLY0uMAJ1Lf8c+z5plDy5sJAXlEreLZplR4KdPd42vYEvSG7qVLapkgNDGEUOqM3YC PTe4JxvUHgj9Fe1M6iuBBubspJNeZAs7OkI1Qc5N+r4lHVKzicEy/zSdtnqAL82uTvDG 5kmueMBgxqMFWFRCH28wdnbVs2BhoTdR8z08mn9o1MnvVGnWsDcU+1Z9R0cX1mO0BwOi 7M46WqKK8ujbCHnUrRPFdTypL+BdR2uh6rshtkFbVsymnsdDD46yvNsFELqDSLCbuAfL c/wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZbaK4P3H; 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 u20si9077957eda.569.2020.06.15.11.23.14; Mon, 15 Jun 2020 11:23:37 -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=ZbaK4P3H; 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 S1731279AbgFOSVM (ORCPT + 99 others); Mon, 15 Jun 2020 14:21:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729124AbgFOSVL (ORCPT ); Mon, 15 Jun 2020 14:21:11 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 869AFC061A0E for ; Mon, 15 Jun 2020 11:21:10 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id b16so8151468pfi.13 for ; Mon, 15 Jun 2020 11:21:10 -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=LemJIWusSKTs9kB/F9oxsCC3XddFJYsF1dwWH4aB1F4=; b=ZbaK4P3Hx9xthr2Qfvlbkdn21ETo+ds9I8Li31Dtpx7O3FLtxpS3690+xjpgt3DD79 mRJ48GsWFsGlU67p0rYiusy/1LL0XjM2GVe3HyodomQeWo9s2js49R5ttjUQX64iPbto wPVfxdeuz81MjY7bhV8ymnTDGXi82DjCqguEI= 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=LemJIWusSKTs9kB/F9oxsCC3XddFJYsF1dwWH4aB1F4=; b=jQWgTvX0FD+bAZMGke4Zk5kPofOfA7CYC/6fkmSj7OzET70pFsHG+KynqV5YB2Dube i3tEEBVoDIXV6dMXV46lws4t11f1Cx+wb9xWptfU5OSzBSZRnWxGFLTQSdCqyQq6jorw dPXrgFxrx0mGzXUPDwm/aOeKiZlpjilwXoVGnQ73Ie3QD+PQwGpoMkcyR5FZBSQQut6X qH0wI6nVil5Kran8q+qmOdONI1pzHLjV8Ecc+P0VsK1euPGGQ9vnWTPsm5ey7BX6sYur 4xHCKJ8Ovph/jeL8LJtYYSK/ijUNgAwwPwonTyHJ2VtaCBtw5iX+BTRW70RvlhlPwg4r HZtA== X-Gm-Message-State: AOAM5321bSlTg5IRh68LvS7TsjnIB2amKLcBpKdaAqmDVAreuEaD0yIg W6nfnE6GXdtK7aq0T2VLm4rACg== X-Received: by 2002:a63:ea02:: with SMTP id c2mr15929639pgi.66.1592245269889; Mon, 15 Jun 2020 11:21:09 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d4sm181377pjm.55.2020.06.15.11.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 11:21:09 -0700 (PDT) Date: Mon, 15 Jun 2020 11:21:08 -0700 From: Kees Cook To: Sami Tolvanen , James Morris Cc: David Howells , "Eric W. Biederman" , KP Singh , Casey Schaufler , Thomas Cedeno , Anders Roxell , linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] security: fix the key_permission LSM hook function type Message-ID: <202006151113.7A2F638A7@keescook> References: <20200615181232.119491-1-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200615181232.119491-1-samitolvanen@google.com> 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: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/ -Kees > --- > include/linux/lsm_hook_defs.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index 6791813cd439..24f6683f1cfc 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -360,7 +360,7 @@ LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred, > unsigned long flags) > LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) > LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, > - unsigned perm) > + enum key_need_perm need_perm) > LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **_buffer) > #endif /* CONFIG_KEYS */ > > > base-commit: b3a9e3b9622ae10064826dccb4f7a52bd88c7407 > -- > 2.27.0.290.gba653c62da-goog > -- Kees Cook