Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4154819ybb; Mon, 23 Mar 2020 14:46:15 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtHNbk3r/7oBIhyPphp7d3jRHj7SSyZ1pxMz6UpxBlw2L1xL7/CFZl/zoEfBd9k1k1S41cs X-Received: by 2002:a9d:6b16:: with SMTP id g22mr2068149otp.37.1584999975405; Mon, 23 Mar 2020 14:46:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584999975; cv=none; d=google.com; s=arc-20160816; b=ou52jqu9OJjT/A5cDfPf+CR01m9q7UJ4RA/VM1rhNzLV2gLiYVEwx8XMRjcHSMR9T+ GDZ1SuZ7euUmTaalWl7soLwgBKDqXm+u10xnqW04IMcZ0VoKglUKBbY+QNk7f4kEhKvV 77VPf4VEooAP1pe5U7ub0ig1TMhunhQGnsrJtDRysErTDY+GXJKwC/5XN/7YeVC11afR omMbU/QmAGYX81lpJE63FHUeTdFpIiw3jiZTyLvpN1+YIYs8aHDPTCG7o0+mzstDELXk cvhEp+d1x2bcn2PdqDZHKcbC8jVZzVul60/LMS2AdG2QG9HnhmN6AWLOU5Mi25eusQ3H XMOg== 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=hEOCvDpxyBMwengYvfMIe1pWY5IozmG+/5v8TyzWx7E=; b=CBU6POKfwGNGC0l3bZtyi6/Ka/z0qXEhv1oQiTvuE8PGmQJigPk+FgpNlThugtZrcY 0MOW2Gy/nI0MJZzfygwUABmsgpOzO6Rs4h+VAf7S9sKmuMGaxE/xLRkWk0YnAsHHG8EQ z312BTaruxobPi4qDw+c4mDgS/Ludo4qMS5T9yFcAPhUZrnaVhCaaIJuosoUs5hn79XW PUYTMZBS422rILtCMLeFfgkmPUM+JUb1vuu8mVgoQgZEh9kWJvBEwifw0bHDACABQ3/h TTYy1V8fOzebfkc1jjjjekc7B0abYuzP7MRMWarwFp86LLtIjl4w5BEvuh9XWaO6FlcE GuZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cY31lTq7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id t132si8348830oih.173.2020.03.23.14.46.02; Mon, 23 Mar 2020 14:46:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cY31lTq7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727117AbgCWVoJ (ORCPT + 99 others); Mon, 23 Mar 2020 17:44:09 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45425 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727005AbgCWVoJ (ORCPT ); Mon, 23 Mar 2020 17:44:09 -0400 Received: by mail-pl1-f193.google.com with SMTP id b9so6484700pls.12 for ; Mon, 23 Mar 2020 14:44:08 -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=hEOCvDpxyBMwengYvfMIe1pWY5IozmG+/5v8TyzWx7E=; b=cY31lTq7BOxMLd+B6z8dKX7c1GMJuNhCFQ2Bvdkmy/khdCyZG1FsLovWzwfE2X4puE RptITITDWaegsUZT6yoqeuJNa76WgCG1fH5jgsi1As+AtzwHN7iuUOnSYCIdpRoGwUb5 Wnqi55UYFSoUBKmaBg5PSmjcREgFlzmrKx9d8= 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=hEOCvDpxyBMwengYvfMIe1pWY5IozmG+/5v8TyzWx7E=; b=CFEg2uYN43pkE1OfdE9PxKlQIz0i1vHCDYrlS78Hkj8fuYP1BVskJvAkr84Bew2EWy 1ENLnMDgPDw6fFxZjuURPjhc8+i5Vy9Y8DpB3IfF7wMASerDxs9F+DZHx8yGnPh2J/Qd 2IxHAE2nFnOPD8j9l04AR3tPxLStXtPuuYKGPLISxNaklzXANkkLF9m5sARqA9sijIvn DfmxI5oUWlOq9IGNUtBTqNF1WQbiQi/ydrjzyYS7CscyCKDO1PJTnDQi24nABwskVydE fj9buuPepuwLKQYtl2dMUfQiVrkOIeDXkIF66rzJJwFMBIdJEqycAI2sTJjdY2HVcFsZ u3Vg== X-Gm-Message-State: ANhLgQ2PBVoeq3jm3sa7TRXdQlOipuW19GwpnGNyHhZfHjH+RZp/d6iU QjfqhOytuDdG5xrtsf7SaglKLg== X-Received: by 2002:a17:90a:346f:: with SMTP id o102mr1542753pjb.162.1584999847690; Mon, 23 Mar 2020 14:44:07 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 73sm13685819pgg.90.2020.03.23.14.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 14:44:06 -0700 (PDT) Date: Mon, 23 Mar 2020 14:44:05 -0700 From: Kees Cook To: Casey Schaufler Cc: KP Singh , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman Subject: Re: [PATCH bpf-next v5 5/7] bpf: lsm: Initialize the BPF LSM hooks Message-ID: <202003231354.1454ED92EC@keescook> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-6-kpsingh@chromium.org> <202003231237.F654B379@keescook> <0655d820-4c42-cf9a-23d3-82dc4fdeeceb@schaufler-ca.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0655d820-4c42-cf9a-23d3-82dc4fdeeceb@schaufler-ca.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 01:47:29PM -0700, Casey Schaufler wrote: > On 3/23/2020 12:44 PM, Kees Cook wrote: > > On Mon, Mar 23, 2020 at 05:44:13PM +0100, KP Singh wrote: > >> +/* Some LSM hooks do not have 0 as their default return values. Override the > >> + * __weak definitons generated by default for these hooks > > If you wanted to avoid this, couldn't you make the default return value > > part of lsm_hooks.h? > > > > e.g.: > > > > LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct inode *inode, > > const char *name, void **buffer, bool alloc) > > If you're going to do that you'll have to keep lsm_hooks.h and security.c > default values in sync somehow. Note that the four functions you've called > out won't be using call_int_hook() after the next round of stacking. I'm not > nixing the idea, I just don't want the default return for the security_ > functions defined in two places. Yeah, I actually went looking for this after I sent the email, realizing that the defaults were also used in security.c. I've been pondering how to keep them from being duplicated. I'm working on some ideas. The four are: inode_getsecurity inode_setsecurity task_prctl xfrm_state_pol_flow_match None of these are already just calling call_int_hook(), but I assume they'll need further tweaks in the coming stacking. To leave things as open-code-able as possible while still benefiting from the macro consolidation, how about something like this: lsm_hook_names.h: LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct inode *inode, const char *name, void **buffer, bool alloc) ... security.c: #define LSM_RET_DEFAULT_void(DEFAULT, NAME) /* */ #define LSM_RET_DEFAULT_int(DEFAULT, NAME) static const int NAME#_default = (DEFAULT); #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ LSM_RET_DEFAULT_#RET(DEFAULT, NAME) #include #undef LSM_HOOK ... Then -EOPNOTSUPP is available as "inode_getsecurity_default": int security_inode_getsecurity(struct inode *inode, const char *name, void **buffer, bool alloc) { struct security_hook_list *hp; int rc; if (unlikely(IS_PRIVATE(inode))) return inode_getsecurity_default; /* * Only one module will provide an attribute with a given name. */ hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity, list) { rc = hp->hook.inode_getsecurity(inode, name, buffer, alloc); if (rc != inode_getsecurity_default) return rc; } return inode_getsecurity_default; } On the other hand, it's only 4 non-default return codes, so maybe the sync burden isn't very high? -- Kees Cook