From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5DB1C433EF for ; Mon, 13 Sep 2021 07:16:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B856C60EE7 for ; Mon, 13 Sep 2021 07:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235494AbhIMHSL (ORCPT ); Mon, 13 Sep 2021 03:18:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20938 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237572AbhIMHSI (ORCPT ); Mon, 13 Sep 2021 03:18:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631517413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3sfiq9gd+F6JH8oSBvW0EmNYJfq7/aiWJpxsGuGmiIY=; b=i3xzIC4VpiHPzKtMBBI51tkkxi9eCXf694hc9ddyiChTMS8M/tlzwE5RtMmnEIvxdQuwYQ LDRmLdG3ktPLdAwd18GM/hnFUqJxHmBNE+thXINK1U9zN0/qv/gMY3MEsEAR9llPz4CLjF cXW+T6N6VPs2tGG16bR4+jjWrZEo9Jg= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-mJH-AaFzONes0YPj73etXA-1; Mon, 13 Sep 2021 03:16:51 -0400 X-MC-Unique: mJH-AaFzONes0YPj73etXA-1 Received: by mail-yb1-f197.google.com with SMTP id 124-20020a251182000000b005a027223ed9so11765915ybr.13 for ; Mon, 13 Sep 2021 00:16:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3sfiq9gd+F6JH8oSBvW0EmNYJfq7/aiWJpxsGuGmiIY=; b=KzFuKFPJttpbDDpe89geyrq1E/RlW4MGfUEhgynG6fo3Zo+/3j1d3Er/25QJYPSJ8r ceYaRtgHni/ihS39poR/uZLSgD8PYMMgyz+2CIDD0Kss4daZJFv660yw+LOJzZ6y4gSI t9duyuSEP7E79ggqmgYZ7MEI2DVX5rjmB8Dfx5fMigjmMLOBlMuzTqTRYBAKfs4Hsy5H IyrHRzdcefVxGxk9zPt28s+XJwkBBtQdHonmi76tJaIsY4HLtISWPBREq6J9KLNPp3Oh HE8AN/scFenCQ9n+tCr0fbEHSBOOP8+eHps6fj8OHTksGLdM2dTY0joYTvU1DpOYqVCF ofYg== X-Gm-Message-State: AOAM530WTl0MkfhymX8INeLtjwDtRGQnbH/LaTf3TdOQOE81r67diAbH E0PiBHZWcYOYVtZdLGpBxmf01CxJhpA/0FU67Rtw9ENLUb8z4E4gIogSUooJu/BHDCne9UKCDFn IWkfN1SnGxG0PuMFWDsxl6cKyf3tEvF/eOF75MgD4 X-Received: by 2002:a25:83:: with SMTP id 125mr13609794yba.467.1631517411148; Mon, 13 Sep 2021 00:16:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7kJQ1PXFrM1GJmwLzxTDCzAnCF4sbmb32hyfGmjO6KYJLAN17PxbqC5KZnDcXxN+lY9MSOWE9m1W7pZXWyqo= X-Received: by 2002:a25:83:: with SMTP id 125mr13609777yba.467.1631517410913; Mon, 13 Sep 2021 00:16:50 -0700 (PDT) MIME-Version: 1.0 References: <20210912122234.GA22469@asgard.redhat.com> In-Reply-To: <20210912122234.GA22469@asgard.redhat.com> From: Ondrej Mosnacek Date: Mon, 13 Sep 2021 09:16:39 +0200 Message-ID: Subject: Re: [PATCH v2] include/uapi/linux/xfrm.h: Fix XFRM_MSG_MAPPING ABI breakage To: Eugene Syromiatnikov Cc: Steffen Klassert , Herbert Xu , "David S. Miller" , Antony Antony , Christian Langrock , Nicolas Dichtel , SElinux list , Paul Moore , Stephen Smalley , Eric Paris , network dev , Linux kernel mailing list , "Dmitry V. Levin" , Linux API Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sun, Sep 12, 2021 at 2:23 PM Eugene Syromiatnikov wrote: > Commit 2d151d39073a ("xfrm: Add possibility to set the default to block > if we have no policy") broke ABI by changing the value of the XFRM_MSG_MAPPING > enum item, thus also evading the build-time check > in security/selinux/nlmsgtab.c:selinux_nlmsg_lookup for presence of proper > security permission checks in nlmsg_xfrm_perms. Fix it by placing > XFRM_MSG_SETDEFAULT/XFRM_MSG_GETDEFAULT to the end of the enum, right before > __XFRM_MSG_MAX, and updating the nlmsg_xfrm_perms accordingly. > > Fixes: 2d151d39073a ("xfrm: Add possibility to set the default to block if we have no policy") > References: https://lore.kernel.org/netdev/20210901151402.GA2557@altlinux.org/ > Signed-off-by: Eugene Syromiatnikov > --- > v2: > - Updated SELinux nlmsg_xfrm_perms permissions table and selinux_nlmsg_lookup > build-time check accordingly. > > v1: https://lore.kernel.org/lkml/20210901153407.GA20446@asgard.redhat.com/ > --- > include/uapi/linux/xfrm.h | 6 +++--- > security/selinux/nlmsgtab.c | 4 +++- > 2 files changed, 6 insertions(+), 4 deletions(-) > > diff --git a/include/uapi/linux/xfrm.h b/include/uapi/linux/xfrm.h > index b96c1ea..26f456b1 100644 > --- a/include/uapi/linux/xfrm.h > +++ b/include/uapi/linux/xfrm.h > @@ -213,13 +213,13 @@ enum { > XFRM_MSG_GETSPDINFO, > #define XFRM_MSG_GETSPDINFO XFRM_MSG_GETSPDINFO > > + XFRM_MSG_MAPPING, > +#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING > + > XFRM_MSG_SETDEFAULT, > #define XFRM_MSG_SETDEFAULT XFRM_MSG_SETDEFAULT > XFRM_MSG_GETDEFAULT, > #define XFRM_MSG_GETDEFAULT XFRM_MSG_GETDEFAULT > - > - XFRM_MSG_MAPPING, > -#define XFRM_MSG_MAPPING XFRM_MSG_MAPPING Perhaps it would be a good idea to put a comment here to make it less likely that this repeats in the future. Something like: /* IMPORTANT: Only insert new entries right above this line, otherwise you break ABI! */ > __XFRM_MSG_MAX > }; > #define XFRM_MSG_MAX (__XFRM_MSG_MAX - 1) > diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c > index d59276f..94ea2a8 100644 > --- a/security/selinux/nlmsgtab.c > +++ b/security/selinux/nlmsgtab.c > @@ -126,6 +126,8 @@ static const struct nlmsg_perm nlmsg_xfrm_perms[] = > { XFRM_MSG_NEWSPDINFO, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, > { XFRM_MSG_GETSPDINFO, NETLINK_XFRM_SOCKET__NLMSG_READ }, > { XFRM_MSG_MAPPING, NETLINK_XFRM_SOCKET__NLMSG_READ }, > + { XFRM_MSG_SETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_WRITE }, > + { XFRM_MSG_GETDEFAULT, NETLINK_XFRM_SOCKET__NLMSG_READ }, > }; > > static const struct nlmsg_perm nlmsg_audit_perms[] = > @@ -189,7 +191,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm) > * structures at the top of this file with the new mappings > * before updating the BUILD_BUG_ON() macro! > */ > - BUILD_BUG_ON(XFRM_MSG_MAX != XFRM_MSG_MAPPING); > + BUILD_BUG_ON(XFRM_MSG_MAX != XFRM_MSG_GETDEFAULT); > err = nlmsg_perm(nlmsg_type, perm, nlmsg_xfrm_perms, > sizeof(nlmsg_xfrm_perms)); > break; > -- > 2.1.4 > -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.