Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1389716rwd; Wed, 7 Jun 2023 15:46:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7NoRxuKrDKi+H+B35a9y3AKvFAk8pSNRae6QTqs4mjAAw+M+bURS2fQKf3t+yWsQUqQx4Q X-Received: by 2002:a17:90a:4585:b0:256:4d27:a300 with SMTP id v5-20020a17090a458500b002564d27a300mr5561688pjg.35.1686177966086; Wed, 07 Jun 2023 15:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686177966; cv=none; d=google.com; s=arc-20160816; b=oCyXx5jp/F4DAggtfS7n50L1itwWBNhKcQTV4Nl4GsjPN1NR9T9XYaGOEzO0JNm59E xTo77zLSkIweX31IK0GNXCGI92WKJSqmc5tQGfnFw3IE0NkRSy5cTf3Er8gXWQzfQK3F BnNf4nXq1Yl7xIp8eEbIbMT0AP6cMpCUuifGuNM+PUIREtMc8+mrTfnnfkkqx3ShYZLk HkvT++Fy3sREumhEzfpdVo7hrOZS6/2xkNrsZHhh5SnH5BxsljrS8il11/TbqdDQNmmW 5rFz/KEQUCGko0DWBmhimRfYEK/9zjupMdQcuif7FA32F9w0aW51h06IczXcO9q8U804 cBTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:subject:cc:to:from :message-id:date:dkim-signature; bh=8llCPG+vVtkPUwjQtiWJ3WQx6JiHNRGSvHVuzeIpYl8=; b=k57teD/yGBolC8IW0ayJBLocjHQ3oCtk5x0UfBsguv0OwTnUScQcREqEuMWJMyCYid nfknW61b2j5rFS0Mw63X5hANC9SqfkgwjXo8H3kxVg9yIBBjtci9Up8D77r+S21/cuhr QQoF5ppw56YdWTUDE7VriNGcnp/B2zzzGQyJRK7sbVYi2IUsMS/gRZIik41ecGRSCrML 8LiZQK8jH2jBsRkhqPEkBzGu6m0um75B/3XoBv+5jwIZva1VqENM8jtVRBqXQ6aJmm3H bXU1nbr7I2snwMcX8Ixm9d35I6lcrtCHHw+roRZ9jSedNf9++4p2MD5Egd5cSVpek+Ob 3ULg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=Teys5iOP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a17090aa08b00b0024df9b42c22si43581pjp.67.2023.06.07.15.45.52; Wed, 07 Jun 2023 15:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paul-moore.com header.s=google header.b=Teys5iOP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=paul-moore.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232960AbjFGWdL (ORCPT + 99 others); Wed, 7 Jun 2023 18:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232053AbjFGWdE (ORCPT ); Wed, 7 Jun 2023 18:33:04 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D8C419B6 for ; Wed, 7 Jun 2023 15:33:01 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id d75a77b69052e-3f6b2af4558so59289991cf.1 for ; Wed, 07 Jun 2023 15:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1686177180; x=1688769180; h=in-reply-to:references:subject:cc:to:from:message-id:date:from:to :cc:subject:date:message-id:reply-to; bh=8llCPG+vVtkPUwjQtiWJ3WQx6JiHNRGSvHVuzeIpYl8=; b=Teys5iOPggBuB4MwMYC4fYT40I07CnWHKp2KVP33MNp7LzhrMhIh6ZjObVDrpqopU6 S65i4AlM1ZRe6MI3inCaIuujJqtHY3mpfIHpgYcW3A2moxi69m94sezvmvs3B/NcLx+7 iU+VVrAlgQt2E7JKi5S6PiaNiVlghFzKR/ARm11fVjxDlhrC+EKlyw5njk6unuVZY8MW EqRLzYpdwLrMOAVx5/6LqgWGEftbBGDSRQ73BGXA1yS4lh7PHIgetQguKtqN2iwwYQrl rwvddBBAltGZgnSQjwVhbs9jpRJ5MjhJTCZCQ/GMvIcTgN17Ae8n/+YiEOm36PPooY7e LhRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686177180; x=1688769180; h=in-reply-to:references:subject:cc:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8llCPG+vVtkPUwjQtiWJ3WQx6JiHNRGSvHVuzeIpYl8=; b=DesQXrf6K3tEjP7Bg8iAn0+6VNFh3XlXzAO3hJNrxsCZhw7sVh/mD5WqmmiiZV/+JV H7uchFuXMuBEuQxlQi5Ufm5ktwmQ5ngNHXu9tvUwKRElS8EizHoE4ecbw01iMx+7g5L8 94MY8vMjvezD2yA82pNddyK5pCOGx3/9CfikbUba+7bdHp9Sls3pKShkJPP6dmIzgsMc d4rsmWjwBuOiqEFWZfrR3QtAhIBiL/C6Q4eVXXgnbUWStrMTsuVwG59g96Vu0cbZPcsc d4lfaSlSwXn6iY28x28NvJqcsE6t0xsKLdeUBFb05Zj8OVZair47IfP1yopQHhjNK7rM VlVg== X-Gm-Message-State: AC+VfDywP1j1TH/QOWiqfImugvawumg6XXfXTbFc8hOY48GPpz8VUWyK CrvgBu3REcE90HBJpSLa3kik X-Received: by 2002:ac8:7f81:0:b0:3f8:6cc0:d663 with SMTP id z1-20020ac87f81000000b003f86cc0d663mr5296197qtj.17.1686177180421; Wed, 07 Jun 2023 15:33:00 -0700 (PDT) Received: from localhost (static-96-237-115-254.bstnma.fios.verizon.net. [96.237.115.254]) by smtp.gmail.com with ESMTPSA id g4-20020ac80704000000b003ef33e02eb9sm230021qth.83.2023.06.07.15.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 15:33:00 -0700 (PDT) Date: Wed, 07 Jun 2023 18:32:59 -0400 Message-ID: From: Paul Moore To: Casey Schaufler , linux-security-module@vger.kernel.org Cc: jmorris@namei.org, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mic@digikod.net, selinux@vger.kernel.org Subject: Re: [PATCH v10 10/11] SELinux: Add selfattr hooks References: <20230428203417.159874-11-casey@schaufler-ca.com> In-Reply-To: <20230428203417.159874-11-casey@schaufler-ca.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Apr 28, 2023 Casey Schaufler wrote: > > Add hooks for setselfattr and getselfattr. These hooks are not very > different from their setprocattr and getprocattr equivalents, and > much of the code is shared. > > Signed-off-by: Casey Schaufler > Cc: selinux@vger.kernel.org > Cc: Paul Moore > --- > security/selinux/hooks.c | 154 +++++++++++++++++++++++++++++++-------- > 1 file changed, 124 insertions(+), 30 deletions(-) > > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c > index 2ee92d3fb79d..e78b955e04f8 100644 > --- a/security/selinux/hooks.c > +++ b/security/selinux/hooks.c > @@ -6542,6 +6559,81 @@ static int selinux_setprocattr(const char *name, void *value, size_t size) > return error; > } > > +static int selinux_getselfattr(unsigned int attr, struct lsm_ctx __user *ctx, > + size_t *size, u32 flags) > +{ > + char *value; > + size_t total_len; > + int len; > + int rc; > + > + len = selinux_lsm_getattr(attr, current, &value); > + if (len < 0) > + return len; > + > + total_len = ALIGN(struct_size(ctx, ctx, len), 8); > + > + if (total_len > *size) > + rc = -E2BIG; Hmm. Since we need to calculate the aligned @total_len value in the LSM specific code, perhaps it doesn't make sense to also do the alignment in lsm_fill_user_ctx(). My apologies, I know I was the one who suggested doing the alignment in a common place previously. > + else if (ctx) > + rc = lsm_fill_user_ctx(ctx, value, len, LSM_ID_SELINUX, 0); > + else > + rc = 1; > + > + *size = total_len; > + if (rc < 0) > + return rc; > + return 1; > +} -- paul-moore.com