Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4411376pxu; Tue, 1 Dec 2020 04:27:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwu7yByy7JShwbLsau+biLO3F/6wSNQzpuo1AbsqzrmMzfviLW2AsvFWPnwA16uFFamh/Rr X-Received: by 2002:a17:906:71d3:: with SMTP id i19mr2737331ejk.187.1606825675898; Tue, 01 Dec 2020 04:27:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606825675; cv=none; d=google.com; s=arc-20160816; b=fXgssTBCbr95rsow37Ln1Y7ggPwG119sOq32jl+Wnv2siySqhBdiyA7w/OGqu4sBSe 3NpNGtt6bFLWD70uaIdY3qPbI5Ifusk7HDdhGpyVawHVRYpecA8SSsbJ0k6qWWaLPeao SiutYk3BYQyomACUX+OSG2AvUcRgC5e6xDn4OgmuNzZasu15u96kIaxsmhZVd3Z50RvF ktDZKKBCSfIXMgOj3DWNwJcYgUWHhlyONl3hog2RVMncQTOgWRjThXGzNJ1ek4g71Svw gBvhRShs55dtcLPjhH2iGfw42Qo0HbmFdP+PjiS+hh1ulvx/nezJ3sD3Jjyl7juBWr/q ZpYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Z2FwklLoMp7Egf9u8WP3hDx0fN64Q0x9HiJR3z7n6Kk=; b=UcY0f7ZsnI0feiT84yD0W/qfNbscdoygRemCSAPvW7+k0+lyktp3Cqg5wz5w+BroEM jYcmThI0H5sF3eScXrN+6znvzDhDtyykSKQQiRpWqQa2T2P69A6OJ96yxqsubaenUSgU jZmlhRAPFSkzWvwkECcwip1Vo7mVEP5crgJeTvLOlWOYmu94SDeRJMWOaK1CjKqJlkrs 3PeCTNI0/RZ5eW6WmKxaHAnH673xR7Fk6Bjiaoicjj7AHRpsz9XdAL2iZOlrtbsP9wvS 0ODdKqCGi2GwG2pZTDpZ6H7gmX9+MTgnAS/gxQRsO05l/CCuWGxYfsC7T5jNa+DppwKK 7zXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=b9Q5GXbd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si805336eju.619.2020.12.01.04.27.23; Tue, 01 Dec 2020 04:27:55 -0800 (PST) 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=@google.com header.s=20161025 header.b=b9Q5GXbd; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387522AbgLAMXZ (ORCPT + 99 others); Tue, 1 Dec 2020 07:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbgLAMXY (ORCPT ); Tue, 1 Dec 2020 07:23:24 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DD3CC0613D3 for ; Tue, 1 Dec 2020 04:22:38 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id a3so4504719wmb.5 for ; Tue, 01 Dec 2020 04:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Z2FwklLoMp7Egf9u8WP3hDx0fN64Q0x9HiJR3z7n6Kk=; b=b9Q5GXbd+nn4jqIxEBLDYv8yiSKV3SzTOVp/VrzFb4iZY4KGG2kVnLb3Y43a99RvBg RYJr9LClCcJ/aQhJQecTAh2E4rPBTAceytr4Jjln4ov9omDpfUy7hGhr/wR/Top2rySM hZXhX4jLqzLPvfpAc3c+p7cT+JgrDfhra9E3ZyzFXPArAWSlVg3wgOCHaGtNeJNDQAln RTPKxvvaYKRGoV14w4+T8rg28J5gXgs/fV4OwPBv8aV+ZHgtSGUAozQjiFLbKveCztB7 quPjqjruHSBH1x3ZuGtTSoyucZA2O+ICFIqtphmd/t8iqOUlnbmBluuLUsMbpgYmIt2o C+kQ== 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=Z2FwklLoMp7Egf9u8WP3hDx0fN64Q0x9HiJR3z7n6Kk=; b=MzoXcQzsPluVaZSIYYa4R0eAZtAKdIfV4JH3pseK7sQr3fveNu8xvDTbrO5zWbRGOV INDMIJsoIFo6VWOFS6ZY4df7d5lf7qgeNU2EH6c781kbVWFj8MH6OonDY+vlvYKM3GrT bPX3Sn6PfTVSVX8zdIuzcxuRf+xa45LIEhJPeeXzkhRlWXAWQQOMQPAyeOsCrw9JW9Bm D5HC52mjHBZi5lwRXpgorte90pql4VyyfJE9wnbkzocWOflk8f2rBa4/OOcfWx0ufllJ M/gzI3bGzt2SItR03apBtP69fjZ+ENN2mTdxK+nk8vKIeJ0duETJFIMrZyBLia3lTuIb zcKw== X-Gm-Message-State: AOAM533RhSzA7AlRhIfv4se6NC1F5FUdVZ0FYtvfB+CbUegtN9gwNsaN PKybHDFnhVhuu2azbSixfJUKOw== X-Received: by 2002:a1c:730c:: with SMTP id d12mr2395276wmb.3.1606825356890; Tue, 01 Dec 2020 04:22:36 -0800 (PST) Received: from google.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id a14sm2678636wmj.40.2020.12.01.04.22.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 04:22:36 -0800 (PST) Date: Tue, 1 Dec 2020 12:22:32 +0000 From: Brendan Jackman To: Yonghong Song Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , KP Singh , Florent Revest , linux-kernel@vger.kernel.org, Jann Horn Subject: Re: [PATCH v2 bpf-next 07/13] bpf: Add BPF_FETCH field / create atomic_fetch_add instruction Message-ID: <20201201122232.GD2114905@google.com> References: <20201127175738.1085417-1-jackmanb@google.com> <20201127175738.1085417-8-jackmanb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 27, 2020 at 08:15:49PM -0800, Yonghong Song wrote: > > > On 11/27/20 9:57 AM, Brendan Jackman wrote: [...] > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index e8b41ccdfb90..cd4c03b25573 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -3602,7 +3602,11 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i > > { > > int err; > > - if (insn->imm != BPF_ADD) { > > + switch (insn->imm) { > > + case BPF_ADD: > > + case BPF_ADD | BPF_FETCH: > > + break; > > + default: > > verbose(env, "BPF_ATOMIC uses invalid atomic opcode %02x\n", insn->imm); > > return -EINVAL; > > } > > @@ -3631,7 +3635,7 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i > > is_pkt_reg(env, insn->dst_reg) || > > is_flow_key_reg(env, insn->dst_reg) || > > is_sk_reg(env, insn->dst_reg)) { > > - verbose(env, "atomic stores into R%d %s is not allowed\n", > > + verbose(env, "BPF_ATOMIC stores into R%d %s is not allowed\n", > > insn->dst_reg, > > reg_type_str[reg_state(env, insn->dst_reg)->type]); > > return -EACCES; > > @@ -3644,8 +3648,20 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i > > return err; > > /* check whether we can write into the same memory */ > > - return check_mem_access(env, insn_idx, insn->dst_reg, insn->off, > > - BPF_SIZE(insn->code), BPF_WRITE, -1, true); > > + err = check_mem_access(env, insn_idx, insn->dst_reg, insn->off, > > + BPF_SIZE(insn->code), BPF_WRITE, -1, true); > > + if (err) > > + return err; > > + > > + if (!(insn->imm & BPF_FETCH)) > > + return 0; > > + > > + /* check and record load of old value into src reg */ > > + err = check_reg_arg(env, insn->src_reg, DST_OP); > > + if (err) > > + return err; > > + > > + return 0; > > } > > static int __check_stack_boundary(struct bpf_verifier_env *env, u32 regno, > > @@ -9501,12 +9517,6 @@ static int do_check(struct bpf_verifier_env *env) > > } else if (class == BPF_STX) { > > enum bpf_reg_type *prev_dst_type, dst_reg_type; > > - if (((BPF_MODE(insn->code) != BPF_MEM && > > - BPF_MODE(insn->code) != BPF_ATOMIC) || insn->imm != 0)) { > > - verbose(env, "BPF_STX uses reserved fields\n"); > > - return -EINVAL; > > - } > > - > > if (BPF_MODE(insn->code) == BPF_ATOMIC) { > > err = check_atomic(env, env->insn_idx, insn); > > if (err) > > @@ -9515,6 +9525,11 @@ static int do_check(struct bpf_verifier_env *env) > > continue; > > } > > + if (BPF_MODE(insn->code) != BPF_MEM && insn->imm != 0) { > > "||" here instead of "&&"? Right - thanks again!