lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 23 Jun 2023 08:16:44 -0700
From:   Sumitra Sharma <sumitraartsy@...il.com>
To:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <martin.lau@...ux.dev>,
        Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        Stanislav Fomichev <sdf@...gle.com>,
        Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
        bpf@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Ira Weiny <ira.weiny@...el.com>, Fabio <fmdefrancesco@...il.com>,
        Deepak R Varma <drv@...lo.com>,
        Sumitra Sharma <sumitraartsy@...il.com>
Subject: [PATCH v4] lib/test_bpf: Call page_address() on page acquired with
 GFP_KERNEL flag

generate_test_data() acquires a page with alloc_page(GFP_KERNEL).
The GFP_KERNEL is typical for kernel-internal allocations.
The caller requires ZONE_NORMAL or a lower zone for direct access.

Therefore the page cannot come from ZONE_HIGHMEM. Thus there's
no need to map it with kmap().

Also, the kmap() is being deprecated in favor of kmap_local_page() [1].

Hence, use a plain page_address() directly.

Since the page passed to the page_address() is not from the highmem
zone, the page_address() function will always return a valid kernel
virtual address and will not return NULL. Hence, remove the check
'if (!ptr)'.

Remove the unused variable 'ptr' and label 'err_free_page'.

[1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com/

Suggested-by: Fabio M. De Francesco <fmdefrancesco@...il.com>
Signed-off-by: Sumitra Sharma <sumitraartsy@...il.com>
---

- Link to v1: https://lore.kernel.org/bpf/20230613073020.GA359792@sumitra.com/T/
- Link to v2: https://lore.kernel.org/all/20230613071756.GA359746@sumitra.com/
- Link to v3: https://lore.kernel.org/all/20230622080729.GA426913@sumitra.com/

Changes in v4:
Reported-by: kernel test robot <lkp@...el.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202306230559.hU5Aonpl-lkp@intel.com/
	- Remove unused label 'err_free_page'.

Changes in v3:
Noted by: Fabio M. De Francesco<fmdefrancesco@...il.com>
	- Remove the check 'if (!ptr)'.
	- Remove the unused variable 'ptr'.
	- Change the commit message.

Changes in v2:
Noted by: Fabio M. De Francesco<fmdefrancesco@...il.com>
	- Remove the kmap() call and call page_address() instead.
	- Change the commit subject and message.

 lib/test_bpf.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index ade9ac672adb..a5cc5f9fc4e8 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -14381,25 +14381,17 @@ static void *generate_test_data(struct bpf_test *test, int sub)
 		 * single fragment to the skb, filled with
 		 * test->frag_data.
 		 */
-		void *ptr;
-
 		page = alloc_page(GFP_KERNEL);
 
 		if (!page)
 			goto err_kfree_skb;
 
-		ptr = kmap(page);
-		if (!ptr)
-			goto err_free_page;
-		memcpy(ptr, test->frag_data, MAX_DATA);
-		kunmap(page);
+		memcpy(page_address(page), test->frag_data, MAX_DATA);
 		skb_add_rx_frag(skb, 0, page, 0, MAX_DATA, MAX_DATA);
 	}
 
 	return skb;
 
-err_free_page:
-	__free_page(page);
 err_kfree_skb:
 	kfree_skb(skb);
 	return NULL;
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ