Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4065403ybb; Mon, 23 Mar 2020 12:48:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtbsfXwpExsV9GqWS5jQ6gUXxOoZ+nGAsMHa040TvI/16R4SOHjBLtbmH6R2wNNp55jA41g X-Received: by 2002:aca:7213:: with SMTP id p19mr771824oic.159.1584992934158; Mon, 23 Mar 2020 12:48:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584992934; cv=none; d=google.com; s=arc-20160816; b=WFMmnph0BTMQPddnDUaW2qRqIpuJ5Q4ZJh3qEHTEEHdbp88dy269X8sIV7lM5uzPsr foCRaPMZiDiC0AJDgHdmYCwhp/FZGfUyxcCok8vw9fZupZc/VdaYPWSid2S9eMKXTli+ +TU0BLSAhl+SMWwIAvuXv/eJN+wYGMi0CZjJ5kOGDvPBskTEFBRYsgbHyq6h/qUluXl8 QTv5+8QogxxXXaV+W7Neo0eNLvZjQaVs0hAiIIZxviCf6bLXByd08ri5hsK4xc/vnvBZ awO1dZQTRLMGj9RwfROFKveQQ0Vn91tzd/AHuhlsEQ2OMutizpKkC6JVErC6dO6ucye3 cYXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=DpJzr60RYH1YHVeyAiSvNUlbvp8CoyZnIEyzGyGJIf0=; b=ixpcAIqetVNR2EhU2Ejo+uvlloQbVNb5uouBeO90CwPpSt2u0cs9XVNHUTpFaIj+9i vca3DBvpdCPAdKjFeyLJHHY9itSRHa0zOw0WMZ0L2ex/f303U8pT4/DmbaU/dBAJdQ8V GifzlezQ8eHZa6fEWADA25DCiX/ppxfizBaY9fom9ZAMVVYyapte62acFqZOxOCUT8ZC guIbHtltDYjija1fKbyZBDWTn/Im07UbXl8vdl3miRgub5exx0g8f60+E3VFLr3kATJg pCKiuiyTphdyyURQ35D1IcjKz8LZkRj4WukbJxFSSvVWtcwClgZhy9s9qwFCSM0sj0fz VWyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YYYArvhM; 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 193si7599652oie.51.2020.03.23.12.48.41; Mon, 23 Mar 2020 12:48:54 -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=YYYArvhM; 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 S1725913AbgCWTsF (ORCPT + 99 others); Mon, 23 Mar 2020 15:48:05 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37090 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725861AbgCWTsF (ORCPT ); Mon, 23 Mar 2020 15:48:05 -0400 Received: by mail-wr1-f67.google.com with SMTP id w10so18686499wrm.4 for ; Mon, 23 Mar 2020 12:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=DpJzr60RYH1YHVeyAiSvNUlbvp8CoyZnIEyzGyGJIf0=; b=YYYArvhMrddRhLjVhyEYKPKfh4GTqwNmNMEUs45MCXfUsTsARG0MPtNgY4fo2iT6Y1 ouXyxE842tFyWhJ5Levjm/QqUPGpTUIj6KunvmQKz4JnVZvP8mVCWgzhHyBUBgdRiXze qAkqWKvEKYkfvAr+IP9NRLtF7ING9QoSE/QCk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=DpJzr60RYH1YHVeyAiSvNUlbvp8CoyZnIEyzGyGJIf0=; b=mgT4wBzXpuDRAr9aXE8OIFmbXwjbvo13gtA/4tmX57eoLFYViSzLX1cyUqm9sc5tot +YqW4lVyFJuspD12I+KWYtvKLuYkqDWCQCP0bSOEon4wncKc+roGyxldCvSOkqdi1dqD xkVErO6wX6K6N4p4vmUvq/F37mYokmzEP2Ue08BKxUz7Q4MS1x0yXw5EQ2CklC4/Sbxw 7r80lKjWdBTm8XeM5hvEE4uaZ54E24vyGRg5P37WiMV4IpsBbvx8mUFqcawnZFKqdnrM D3Q09vVKYSbMobnpJqeGK4YlaAlml6Gj3/YxrioSHdrLESVLWeiUun7gJTBy6zUF1tZT w7eg== X-Gm-Message-State: ANhLgQ1e6ylixrL5TnVO6JTbYVQlBhhP117Qjf8BGStRgea9DRMt0p08 KwHmMOSbFyh+LwW9bn0KDBrrkg== X-Received: by 2002:adf:b31d:: with SMTP id j29mr17628886wrd.218.1584992882202; Mon, 23 Mar 2020 12:48:02 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id s7sm24212509wri.61.2020.03.23.12.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 12:48:01 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Mon, 23 Mar 2020 20:47:59 +0100 To: Kees Cook Cc: 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: <20200323194759.GB18787@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-6-kpsingh@chromium.org> <202003231237.F654B379@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202003231237.F654B379@keescook> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23-M?r 12:44, Kees Cook wrote: > On Mon, Mar 23, 2020 at 05:44:13PM +0100, KP Singh wrote: > > From: KP Singh > > > > The bpf_lsm_ nops are initialized into the LSM framework like any other > > LSM. Some LSM hooks do not have 0 as their default return value. The > > __weak symbol for these hooks is overridden by a corresponding > > definition in security/bpf/hooks.c > > > > The LSM can be enabled / disabled with CONFIG_LSM. > > > > Signed-off-by: KP Singh > > Nice! This is super clean on the LSM side of things. :) > > One note below... > > > Reviewed-by: Brendan Jackman [...] > > + > > +/* > > + * Copyright (C) 2020 Google LLC. > > + */ > > +#include > > +#include > > + > > +/* 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) > > ... > > #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ > LSM_HOOK_##RET(NAME, DEFAULT, __VA_ARGS__) > ... > #define LSM_HOOK_int(NAME, DEFAULT, ...) \ > noinline int bpf_lsm_##NAME(__VA_ARGS__) \ > { \ > return (DEFAULT); \ > } > > Then all the __weak stuff is gone, and the following 4 functions don't > need to be written out, and the information is available to the macros > if anyone else might ever want it. Thanks, I like it! If no-one objects, I will update it in the next revision. - KP > > -Kees > > > + */ > > +noinline int bpf_lsm_inode_getsecurity(struct inode *inode, const char *name, > > + void **buffer, bool alloc) > > +}; [...] > > -- > > 2.20.1 > > > > -- > Kees Cook