Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3900861ybf; Tue, 3 Mar 2020 15:22:20 -0800 (PST) X-Google-Smtp-Source: ADFU+vtwSvqyECMzTSuOV57dBR3YkeqfeKmWRrbXdkXCtycsQmrY8qA1QEVH34R9m12+duDMP8MO X-Received: by 2002:aca:e084:: with SMTP id x126mr642276oig.97.1583277740687; Tue, 03 Mar 2020 15:22:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583277740; cv=none; d=google.com; s=arc-20160816; b=eRa/ProuGjCcAyn7A4XrSQr21y3ZrNqbDmAnejtuX9rm8QL1pgt15/hkHywsmYbWl0 eyuNeoqEUJc2ZGEaJrP7Vj6L8mXq9+e+xJk1Ea0k5f4PDq8HB947fhxTfnZU6blMY6Wi PjvgEXc2KBiG68gbhhF42dm8jKRIJaoB6mzZQdgxiLWdPiLh3ZqfzGolABJ6qR3Wp8Nu UF526Ze7juFQLSDeF3SEpfSl1zVnvvxoon46g2vnVLy0OB8hDtTM9QWErOtTJ42qTNnr 3gzabC1TS0ijMQjlzqqcl0g6hIOLC4uGv5MUXp0ncJ694isBjXYmfEWwjuJeHIdy6m// P6hQ== 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=FQrFyte0eQhkHV1ZGTXUg6vu0R7T0FUdhPvhOFpCIYA=; b=xzklxAi0S8wqMPepFpAjGyruCcfx4sXq/MlbxAv7sDGadUWLbzyFFTVoMzGo2Nj775 mk4K5dGQeFwqA8LrVZr15OcHqPZUXqjhp4MmotCQhUVsjbO7Tsr+lXrU6plwHxYxBb5P XiN0OQUg34hvuWKvI9PGAHoKEdWcCQyXbZCUEe7fK0el5av6VfTBhwID+LvwRnbUJVIF w3ECbiuuICtGOB1CU0Ae25rfzJjdl0Venx5j7NkyQh87ztqHR77vn25f0m0OunM4b3Ye nP6Cx+Wk2S/qaZGR4zPt4sfqExzi7wpDuuA7IVTuR88axQcD5i+UQgZxxdLgWqWCZ2ar Ft+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iPsFgD2j; 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 d20si46282oti.311.2020.03.03.15.22.07; Tue, 03 Mar 2020 15:22:20 -0800 (PST) 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=iPsFgD2j; 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 S1728081AbgCCXV4 (ORCPT + 99 others); Tue, 3 Mar 2020 18:21:56 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35609 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727888AbgCCXVz (ORCPT ); Tue, 3 Mar 2020 18:21:55 -0500 Received: by mail-wm1-f65.google.com with SMTP id m3so4690690wmi.0 for ; Tue, 03 Mar 2020 15:21:54 -0800 (PST) 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=FQrFyte0eQhkHV1ZGTXUg6vu0R7T0FUdhPvhOFpCIYA=; b=iPsFgD2jDudXd8oLP5/RlUPiFg4J+72znOLJ5Ska9NJYuN99ZocKhyYTnQVFFC/LYp u6mNao0Vp2XS2KzVSf1XBteBO+5kJ7EANKwnUK6BiGc/5vvrMIYMgMuBXVgy8gXML8s7 d6qQHWKI2j/SbPHE1yEpdE+jr78Ln7Kzjfk7c= 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=FQrFyte0eQhkHV1ZGTXUg6vu0R7T0FUdhPvhOFpCIYA=; b=R2RZe2pifHc0ipLFD9htxwADxmx7vr8FZOj1Mpkagd2/0T/0EGR2DitptqSP6t8+ae c3P5l0qaCEZM4yplbpenLxf43g4g0VtXY6Z3Guej5HOI4AiLqc33fGU64IlW1fbH7Vat xXbMvl2YqUBVLVFYRBXyhqRE6eBc87jeDwRnDbgX4vAh2+qxyiVdG9z0Kwc4YFCFMQH4 3+nKeX9IBUa2NapN5QBwn3VZOMCbA2e7EWxj7prBPtzssvGf5+BwXlTnxsM2T8yyWB2k Yh272yupXxf2Toy5MGFl/3g/lBDNVD55E5WpVMBKoyTSFlu9FPJkh+7JaS+Ay2nmZqBz LAJQ== X-Gm-Message-State: ANhLgQ0l6R34mEe2sJpzaRRECGYnAMfZo+7EMqVwS/1vKjBuV9SyKpO+ xkxOielEdFS9I0fGQfHTfqV3Dg== X-Received: by 2002:a05:600c:2c44:: with SMTP id r4mr24028wmg.140.1583277713458; Tue, 03 Mar 2020 15:21:53 -0800 (PST) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id y139sm983960wmd.24.2020.03.03.15.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 15:21:53 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Wed, 4 Mar 2020 00:21:51 +0100 To: Andrii Nakryiko Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Subject: Re: [PATCH bpf-next 4/7] bpf: Attachment verification for BPF_MODIFY_RETURN Message-ID: <20200303232151.GB17103@chromium.org> References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-5-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 03-M?r 14:44, Andrii Nakryiko wrote: > On Tue, Mar 3, 2020 at 6:12 AM KP Singh wrote: > > > > From: KP Singh > > > > - Functions that are whitlisted by for error injection i.e. > > within_error_injection_list. > > - Security hooks, this is expected to be cleaned up after the KRSI > > patches introduce the LSM_HOOK macro: > > > > https://lore.kernel.org/bpf/20200220175250.10795-1-kpsingh@chromium.org/ > > Commit message can use a bit more work for sure. Why (and even what) > of the changes is not really explained well. Added some more details. > > > > > - The attachment is currently limited to functions that return an int. > > This can be extended later other types (e.g. PTR). > > > > Signed-off-by: KP Singh > > --- > > kernel/bpf/btf.c | 28 ++++++++++++++++++++-------- > > kernel/bpf/verifier.c | 31 +++++++++++++++++++++++++++++++ > > 2 files changed, 51 insertions(+), 8 deletions(-) > > [...] > > + t = btf_type_skip_modifiers(btf, t->type, NULL); > > + if (!btf_type_is_int(t)) { > > Should the size of int be verified here? E.g., if some function > returns u8, is that ok for BPF program to return, say, (1<<30) ? Would this work? if (size != t->size) { bpf_log(log, "size accessed = %d should be %d\n", size, t->size); return false; } - KP > > > + bpf_log(log, > > + "ret type %s not allowed for fmod_ret\n", > > + btf_kind_str[BTF_INFO_KIND(t->info)]); > > + return false; > > + } > > + } > > } else if (arg >= nr_args) { > > bpf_log(log, "func '%s' doesn't have %d-th argument\n", > > tname, arg + 1); > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 2460c8e6b5be..ae32517d4ccd 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -19,6 +19,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "disasm.h" > > > > @@ -9800,6 +9801,33 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env) > > > > return 0; > > } > > +#define SECURITY_PREFIX "security_" > > + > > +static int check_attach_modify_return(struct bpf_verifier_env *env) > > +{ > > + struct bpf_prog *prog = env->prog; > > + unsigned long addr = (unsigned long) prog->aux->trampoline->func.addr; > > + > > + if (within_error_injection_list(addr)) > > + return 0; > > + > > + /* This is expected to be cleaned up in the future with the KRSI effort > > + * introducing the LSM_HOOK macro for cleaning up lsm_hooks.h. > > + */ > > + if (!strncmp(SECURITY_PREFIX, prog->aux->attach_func_name, > > + sizeof(SECURITY_PREFIX) - 1)) { > > + > > + if (!capable(CAP_MAC_ADMIN)) > > + return -EPERM; > > + > > + return 0; > > + } > > + > > + verbose(env, "fmod_ret attach_btf_id %u (%s) is not modifiable\n", > > + prog->aux->attach_btf_id, prog->aux->attach_func_name); > > + > > + return -EINVAL; > > +} > > > > static int check_attach_btf_id(struct bpf_verifier_env *env) > > { > > @@ -10000,6 +10028,9 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) > > } > > tr->func.addr = (void *)addr; > > prog->aux->trampoline = tr; > > + > > + if (prog->expected_attach_type == BPF_MODIFY_RETURN) > > + ret = check_attach_modify_return(env); > > out: > > mutex_unlock(&tr->mutex); > > if (ret) > > -- > > 2.20.1 > >