From nobody Fri May 3 13:28:33 2024 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1616947989; cv=none; d=zohomail.com; s=zohoarc; b=mYfO6lYRSuBMDv87/1gDkGFV/CMcI+lRGfbirgtZu9zOzxEEupFe1W00MVIG5xSHhTjzMbGnZUE7Pg52uknqbdV7Y812J54Yn7T1BAz4GQk79SpoLdSNekuF5VkIkYfta/Eiov9CFc51uzcdlxNVbetYdU/4C+e+KjnFASbH75E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616947989; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Subject:To; bh=EoB1lzpwxAqyu9em5N+FxcoQ8XVr6mBu39binMjHk4s=; b=mGryD6Gajkg8FfXh+jvGIrA8W7g+NQnUUbUWe6Mv1IC7xMg2ZMDDKq86PRT8c96klybgwVFhQLUPl2/MpfmT0RyKaS6fqmJEHVJCJ15aBbSNVN2vuGcQvAh8z4WYpV5vglz6S939fNFDwgLkA6WX+elHDCJs7ofQH0CdE8LJ3js= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 161694798933281.08212739364137; Sun, 28 Mar 2021 09:13:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbhC1QMg (ORCPT ); Sun, 28 Mar 2021 12:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbhC1QMT (ORCPT ); Sun, 28 Mar 2021 12:12:19 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D9DCC061756; Sun, 28 Mar 2021 09:12:19 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id l13so7733805qtu.9; Sun, 28 Mar 2021 09:12:19 -0700 (PDT) Received: from localhost.localdomain ([179.218.4.27]) by smtp.gmail.com with ESMTPSA id o7sm11275232qkb.104.2021.03.28.09.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 09:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EoB1lzpwxAqyu9em5N+FxcoQ8XVr6mBu39binMjHk4s=; b=Wxoep/cEAj+Tq6gmNkUBd1h8eDxK2s8DsrD0u0QVXkDDhksgXUF7RzylmGKA6JZBh6 shglOGvmkIri/7ycrZGAoY7OXP1p8St5iw0R/Aa/UPEMYtb1A2bp3HHaoLxL1ryg8Zyr GO2RBGiRItEP/70K1JFd1IeA3pnrldH0zxq2lpBWWG+rUXqlCL3kJHeLr8qVaGdMrBQ8 Iqnv6qJVNX+A7tgPODPt5MhV6Y8wMd+yIKm8VrpREO26qHeBX7g7gSju1q6yRc7HOWs5 IopJipqSJ+GNFmonbpzO0CNbvIMGy0A+M/Lxx/FkgAkX3LPqMuVJDgPekUbwtBPog4yN RP3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EoB1lzpwxAqyu9em5N+FxcoQ8XVr6mBu39binMjHk4s=; b=V6MYtfF0lpPbwOzoeVQW986wuEseRWnquNQxBm00oXS8WZ7+BlYFcNpGkq47gYnP0P wEzpXT3moX9HsDIaqiWuAHtcNR7W5A/oWldMv5wWjKHV90xUAsQAijoyTxner5/C+pmN RFLM5vcm9mwZbnNPU373z6FSS5g0C83NA1Ug2qg1pCVIXjvisR76/TqYRW05W+nnF53R OSA7COh5oe1xgkZnicxo3SV03r9csNpSbuf1GRuHAxvs2n9n2yQ9lgygLXpRdzV18pic ZfIL9ncI3J0/RM5RIDQy2YXOgEeP0xhBm3c99yY/6qqbqGiuariBq/j+3tKTEv9vRFU8 XGsA== X-Gm-Message-State: AOAM53327w5bKypurYa47SbfaMg7SISQlDqHryiEWbnNLU/4LxSkhEY3 +HPW5wmmpGk9tud7PQOOUns= X-Google-Smtp-Source: ABdhPJxa6nd3aqepLvErlJ9Ev8tSzRlw1CqYdwAeShDlpBaokev8LcBhp0H3Gv6qKO4d/DUa2Bn6Vg== X-Received: by 2002:ac8:702:: with SMTP id g2mr19879403qth.215.1616947938463; Sun, 28 Mar 2021 09:12:18 -0700 (PDT) From: Pedro Tammela X-Google-Original-From: Pedro Tammela Cc: Pedro Tammela , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , Joe Stringer , Quentin Monnet , Yang Li , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next] bpf: check flags in 'bpf_ringbuf_discard()' and 'bpf_ringbuf_submit()' Date: Sun, 28 Mar 2021 13:10:31 -0300 Message-Id: <20210328161055.257504-2-pctammela@mojatatu.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210328161055.257504-1-pctammela@mojatatu.com> References: <20210328161055.257504-1-pctammela@mojatatu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The current code only checks flags in 'bpf_ringbuf_output()'. Signed-off-by: Pedro Tammela --- include/uapi/linux/bpf.h | 8 ++++---- kernel/bpf/ringbuf.c | 13 +++++++++++-- tools/include/uapi/linux/bpf.h | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 100cb2e4c104..232b5e5dd045 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -4073,7 +4073,7 @@ union bpf_attr { * Valid pointer with *size* bytes of memory available; NULL, * otherwise. * - * void bpf_ringbuf_submit(void *data, u64 flags) + * int bpf_ringbuf_submit(void *data, u64 flags) * Description * Submit reserved ring buffer sample, pointed to by *data*. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification @@ -4083,9 +4083,9 @@ union bpf_attr { * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification * of new data availability is sent unconditionally. * Return - * Nothing. Always succeeds. + * 0 on success, or a negative error in case of failure. * - * void bpf_ringbuf_discard(void *data, u64 flags) + * int bpf_ringbuf_discard(void *data, u64 flags) * Description * Discard reserved ring buffer sample, pointed to by *data*. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification @@ -4095,7 +4095,7 @@ union bpf_attr { * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification * of new data availability is sent unconditionally. * Return - * Nothing. Always succeeds. + * 0 on success, or a negative error in case of failure. * * u64 bpf_ringbuf_query(void *ringbuf, u64 flags) * Description diff --git a/kernel/bpf/ringbuf.c b/kernel/bpf/ringbuf.c index f25b719ac786..f76dafe2427e 100644 --- a/kernel/bpf/ringbuf.c +++ b/kernel/bpf/ringbuf.c @@ -397,26 +397,35 @@ static void bpf_ringbuf_commit(void *sample, u64 flag= s, bool discard) =20 BPF_CALL_2(bpf_ringbuf_submit, void *, sample, u64, flags) { + if (unlikely(flags & ~(BPF_RB_NO_WAKEUP | BPF_RB_FORCE_WAKEUP))) + return -EINVAL; + bpf_ringbuf_commit(sample, flags, false /* discard */); + return 0; } =20 const struct bpf_func_proto bpf_ringbuf_submit_proto =3D { .func =3D bpf_ringbuf_submit, - .ret_type =3D RET_VOID, + .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_ALLOC_MEM, .arg2_type =3D ARG_ANYTHING, }; =20 BPF_CALL_2(bpf_ringbuf_discard, void *, sample, u64, flags) { + + if (unlikely(flags & ~(BPF_RB_NO_WAKEUP | BPF_RB_FORCE_WAKEUP))) + return -EINVAL; + bpf_ringbuf_commit(sample, flags, true /* discard */); + return 0; } =20 const struct bpf_func_proto bpf_ringbuf_discard_proto =3D { .func =3D bpf_ringbuf_discard, - .ret_type =3D RET_VOID, + .ret_type =3D RET_INTEGER, .arg1_type =3D ARG_PTR_TO_ALLOC_MEM, .arg2_type =3D ARG_ANYTHING, }; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 3d6d324184c0..d19c8c2688a2 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -4073,7 +4073,7 @@ union bpf_attr { * Valid pointer with *size* bytes of memory available; NULL, * otherwise. * - * void bpf_ringbuf_submit(void *data, u64 flags) + * int bpf_ringbuf_submit(void *data, u64 flags) * Description * Submit reserved ring buffer sample, pointed to by *data*. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification @@ -4083,9 +4083,9 @@ union bpf_attr { * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification * of new data availability is sent unconditionally. * Return - * Nothing. Always succeeds. + * 0 on success, or a negative error in case of failure. * - * void bpf_ringbuf_discard(void *data, u64 flags) + * int bpf_ringbuf_discard(void *data, u64 flags) * Description * Discard reserved ring buffer sample, pointed to by *data*. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification @@ -4095,7 +4095,7 @@ union bpf_attr { * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification * of new data availability is sent unconditionally. * Return - * Nothing. Always succeeds. + * 0 on success, or a negative error in case of failure. * * u64 bpf_ringbuf_query(void *ringbuf, u64 flags) * Description --=20 2.25.1