Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1574509pxb; Mon, 13 Sep 2021 00:19:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwJrV6gZgRY/ytGr6xHaHQQJzndfskYxleqsDx1rvJvWKS3PFNY68Us6Hj4xIJRWxe771o X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr11389428ejr.318.1631517540699; Mon, 13 Sep 2021 00:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631517540; cv=none; d=google.com; s=arc-20160816; b=E/z5s2XLX5Z9RMEh7NEdRWZ7xWq0VcO+rkiS3JsM0tbx5q9LzzAgmPuZvVyzVTBGzV g5vNj2C+fEfVNdygp975wF/U6y9s1zi7g2iVnzpOcVkTuRD3diko09pwsBmvhULKgSWc wDGRbKtyUTxnXONxusmnNrojGIaXMNwfwbL0fiF/jeFoJPgMBJQsxUS5nJM6BZZhDuxa qCqlNeI4KkINbMsHUTjKbkrRDSv3ndqQDtxqTH6xQluY5zElAW+jzfK9RpkC8kau5Qey NO8wbUJV5rVEGqyLqcRFGDa6xPUv84cvoDEIgiTku5J243pQ2PsY2hcLFmdzhGnE9viE NGqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3sfiq9gd+F6JH8oSBvW0EmNYJfq7/aiWJpxsGuGmiIY=; b=uoQkR3J4DTDNGri7QWjPKOR7nWSjWIbSuHo8323wJ00WmUdtYjNa+fzC0Snh6FnX4E tudJshoHdkda9J1YaD0mAlsECaBMkx3GWfrLYCh7NsRxPUN4tKzhPXVJZ3HLtOLu40YN 9RNt1L5NnvDRFOhESM+i7K8PljSxd57jT4wXE7APbVC9VieIFndJ7tZXaUwguIbk9grh wLyx7GFFAPmxfC5+PaVhrNGHhQaPhbURkZr9KuDOki4jEN18LXsXs/VSZPJjR74wH9jF RgTe7uxfeN++a+tmZeSTefziNxtRF4+KpKtR8hBFLLE1cqVDgwCzduDzBMHJklw1QRTv RJbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=i3xzIC4V; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si5022316edc.309.2021.09.13.00.18.36; Mon, 13 Sep 2021 00:19:00 -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=@redhat.com header.s=mimecast20190719 header.b=i3xzIC4V; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237557AbhIMHSK (ORCPT + 99 others); Mon, 13 Sep 2021 03:18:10 -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-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.