Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2828131pxb; Mon, 1 Nov 2021 02:40:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbhJTXazOtDfnB9Qh8dA4oycQ+0knnQiAiu2TK1J+zmhLcTQBZnZnSUVqOma2+dFsUSRtR X-Received: by 2002:a17:906:260e:: with SMTP id h14mr12949902ejc.335.1635759626951; Mon, 01 Nov 2021 02:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635759626; cv=none; d=google.com; s=arc-20160816; b=Ey6V0KP61C6PhJzU5D0mYh/dya+fMg4UAcZVI533bM1VCjk2S5Gi9il0dGcOc3U+Aq iK5NeXpZTxYQB9xZYiUkGZculKL8eQPTRpAo0e3lX41/fXZG4qLkhlbm7ZuKPMbvixIR ubQLXz8timC6raTA5SYMuR1mfmxgaqPv1TE5ONvp4Nw8VXM8N9CWeZtc05mJiClkURaG 6426tfDaX4khomxqf8qi7gGBVU6odoBINbNQU59wakCbWttuCsOY7a9hjsOVoGlzCoYl PJvgT4AhViBTJvjCrQnUgwBzFRI3V0MEMyNvlAAB3+T3WFVvn5de+ry602hWjAxxYPRH FjcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dvvd6XwNm8cAJtCdIUYv/CBKKEJq0ZKERfXRmEEEE4E=; b=lli9x9ygKMijzoD3pGBO2ktz6GqHnsrPVSyrAvkZa1TzEVZX0on9mQYrcnC1Aqi6wD aOJEqMs+JolU7HYVoi0k/R3KC3JePvqLHYGO3D/jg+Xa8HQg14wCfhtFpxFWFtYbvXbV vUJhBfiInibYSamdzxyIknjmXc1bSbPJHxNsCy4EZ2vGw9//R6ySAjbFxzzzyK8hGSND YVBCH67KmmtH3OzIiMPpqgtKpDolpihyMG6q02Fty/BRhHmS26Rl3LLI2DIkveB04N6y /3XY9AYzUk18kG4ScfYn0XGX4xkZ3tB0wA5aPPo7dvQSQF27FwKV4dZYv4YDxlmvnVtF yegg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qwBcLc4S; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp7si5554113ejc.755.2021.11.01.02.40.03; Mon, 01 Nov 2021 02:40:26 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=qwBcLc4S; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233698AbhKAJkr (ORCPT + 99 others); Mon, 1 Nov 2021 05:40:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:43646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233709AbhKAJhx (ORCPT ); Mon, 1 Nov 2021 05:37:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A7DA6135A; Mon, 1 Nov 2021 09:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758814; bh=pCmfhynfVRMTz77d99mvKRVIv+QqsiCuApemwBRjFkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwBcLc4SLMBovlPx4qPx4bCiwfvC4PHE68jxH3FWoIgx312xlfE7/LGHg/fHokbHk AkUBV7B1TOFuBVBZzG4wssL5a7lDlfEgXRX0Sm0emq5XTioz5ETR9YhYaB0/uuieTM qbTzrY17p9YxYjFaDTIl19ZMaH9aagMT39DF+U14= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xu Kuohai , Alexei Starovoitov Subject: [PATCH 5.10 38/77] bpf: Fix error usage of map_fd and fdget() in generic_map_update_batch() Date: Mon, 1 Nov 2021 10:17:26 +0100 Message-Id: <20211101082519.913605339@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xu Kuohai commit fda7a38714f40b635f5502ec4855602c6b33dad2 upstream. 1. The ufd in generic_map_update_batch() should be read from batch.map_fd; 2. A call to fdget() should be followed by a symmetric call to fdput(). Fixes: aa2e93b8e58e ("bpf: Add generic support for update and delete batch ops") Signed-off-by: Xu Kuohai Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20211019032934.1210517-1-xukuohai@huawei.com Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/syscall.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1309,12 +1309,11 @@ int generic_map_update_batch(struct bpf_ void __user *values = u64_to_user_ptr(attr->batch.values); void __user *keys = u64_to_user_ptr(attr->batch.keys); u32 value_size, cp, max_count; - int ufd = attr->map_fd; + int ufd = attr->batch.map_fd; void *key, *value; struct fd f; int err = 0; - f = fdget(ufd); if (attr->batch.elem_flags & ~BPF_F_LOCK) return -EINVAL; @@ -1339,6 +1338,7 @@ int generic_map_update_batch(struct bpf_ return -ENOMEM; } + f = fdget(ufd); /* bpf_map_do_batch() guarantees ufd is valid */ for (cp = 0; cp < max_count; cp++) { err = -EFAULT; if (copy_from_user(key, keys + cp * map->key_size, @@ -1358,6 +1358,7 @@ int generic_map_update_batch(struct bpf_ kfree(value); kfree(key); + fdput(f); return err; }