From patchwork Thu Jan 21 02:08:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pan Bian X-Patchwork-Id: 12034211 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97011C433E6 for ; Thu, 21 Jan 2021 02:33:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63F9C2388B for ; Thu, 21 Jan 2021 02:33:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390711AbhAUCWM (ORCPT ); Wed, 20 Jan 2021 21:22:12 -0500 Received: from mail-m972.mail.163.com ([123.126.97.2]:53878 "EHLO mail-m972.mail.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731645AbhAUCK7 (ORCPT ); Wed, 20 Jan 2021 21:10:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=dqcHSmHAfDMQIlJJSN 4wpg35l5Qu7xOOGot1v9uNrfM=; b=UgmHeHyANBrnjbaK385ZOUqyGsjLPTuKDn eWRvRXkJEfe8xSkV4O64KNYx2gH67NXhxRI3li7uZBRiRbySOG+9Hl0BQcQIg/yi 35JhfhxgaCg6fiQ34Eehrp3bd5qKTffj+uX5udyRhnNkbwTLGZNhmTdUqgq1zg0y gWvY3oUYQ= Received: from localhost.localdomain (unknown [119.3.119.20]) by smtp2 (Coremail) with SMTP id GtxpCgCnEcw+4ghgGLEmJw--.3551S4; Thu, 21 Jan 2021 10:09:06 +0800 (CST) From: Pan Bian To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH] bpf: put file handler if no storage found Date: Wed, 20 Jan 2021 18:08:56 -0800 Message-Id: <20210121020856.25507-1-bianpan2016@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: GtxpCgCnEcw+4ghgGLEmJw--.3551S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jry8KryxArWkKry5Cw4rXwb_yoWfZrb_XF WUX3yxKr4q9rZ7Xws8CaySq3s2yF4rKr1kC347KF4UG3Z8Z3s8JFnrAwnxZFyrtw4rKFZx JrZ3Zr95Gr15ZjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU1BbytUUUUU== X-Originating-IP: [119.3.119.20] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBUQIhclaD9tYxSgAAsO Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Put file f if inode_storage_ptr() returns NULL. Fixes: 8ea636848aca ("bpf: Implement bpf_local_storage for inodes") Acked-by: KP Singh Signed-off-by: Pan Bian --- kernel/bpf/bpf_inode_storage.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c index 6edff97ad594..089d5071d4fc 100644 --- a/kernel/bpf/bpf_inode_storage.c +++ b/kernel/bpf/bpf_inode_storage.c @@ -125,8 +125,12 @@ static int bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key, fd = *(int *)key; f = fget_raw(fd); - if (!f || !inode_storage_ptr(f->f_inode)) + if (!f) + return -EBADF; + if (!inode_storage_ptr(f->f_inode)) { + fput(f); return -EBADF; + } sdata = bpf_local_storage_update(f->f_inode, (struct bpf_local_storage_map *)map,