SUNRPC: Fix gss_free_in_token_pages()
Subsystems (3)
[email protected]
maintainerPATCH 1/1 SUNRPC: Fix gss_free_in_token_pages()
From: Chuck Lever <[email protected]>
Commit 5866efa8cbfb ("SUNRPC: Fix svcauth_gss_proxy_init()") from Oct 24, 2019 (linux-next), leads to the following Smatch static checker warning:
net/sunrpc/auth_gss/svcauth_gss.c:1039 gss_free_in_token_pages() warn: iterator 'i' not incremented
net/sunrpc/auth_gss/svcauth_gss.c
1034 static void gss_free_in_token_pages(struct gssp_in_token *in_token)
1035 {
1036 u32 inlen;
1037 int i;
1038
--> 1039 i = 0;
1040 inlen = in_token->page_len;
1041 while (inlen) {
1042 if (in_token->pages[i])
1043 put_page(in_token->pages[i]);
^This puts page zero over and over.
1044 inlen -= inlen > PAGE_SIZE ? PAGE_SIZE : inlen;
1045 }
1046
1047 kfree(in_token->pages);
1048 in_token->pages = NULL;
1049 }--- net/sunrpc/auth_gss/svcauth_gss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/auth_gss/svcauth_gss.c +1 -1
@@ -1040,7 +1040,7 @@ static void gss_free_in_token_pages(struct gssp_in_token *in_token) inlen = in_token->page_len;while (inlen) {if (in_token->pages[i]) -put_page (in_token->pages[i]); +put_page (in_token->pages[i++]); inlen -= inlen >PAGE_SIZE ?PAGE_SIZE : inlen; }
base-commit: 939cb14d51a150e3c12ef7a8ce0ba04ce6131bd2
Signature · 1 line
2.44.0
Quoted 46 lines · On Mon, 2024-05-06 at 16:52 -0400, [email protected] wrote:
From: Chuck Lever <[email protected]>
Commit
5866efa8cbfb("SUNRPC: Fixsvcauth_gss_proxy_init()") from Oct 24, 2019 (linux-next), leads to the following Smatch static checker warning:net/sunrpc/auth_gss/svcauth_gss.c:1039
gss_free_in_token_pages()
warn: iterator 'i' not incremented
net/sunrpc/auth_gss/svcauth_gss.c
1034 static voidgss_free_in_token_pages(struct gssp_in_token *in_token)
1035 {
1036 u32 inlen;
1037 int i;
1038
--> 1039 i = 0;
1040 inlen =in_token->page_len;
1041 while (inlen) {
1042 if (in_token->pages[i])
1043put_page(in_token->pages[i]); ^ This puts page zero over and over.1044 inlen -= inlen >
PAGE_SIZE?PAGE_SIZE:
inlen;
1045 }
1046
1047kfree(in_token->pages);
1048in_token->pages= NULL;
1049 }Reported-by Dan Carpenter <[email protected]>Fixes 5866efa8cbfb ("SUNRPC: Fix svcauth_gss_proxy_init()")Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/auth_gss/svcauth_gss.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)net/sunrpc/auth_gss/svcauth_gss.c +0
-0
net/sunrpc/auth_gss/svcauth_gss.c static void gss_free_in_token_pages(struct · line 1044
Quoted 6 lines
net/sunrpc/auth_gss/svcauth_gss.c +1
-1@@ -1040,7 +1040,7 @@ static void gss_free_in_token_pages(struct gssp_in_token *in_token) inlen = in_token->page_len; while (inlen) { if (in_token->pages[i]) -put_page (in_token->pages[i]); +put_page (in_token->pages[i++]);
Wouldn't it be both more efficient and transparent just to break out of the loop once you hit a NULL page? You already know the remainder of the array will also be NULL.
Quoted 5 lines
net/sunrpc/auth_gss/svcauth_gss.c +0
-0inlen -= inlen > PAGE_SIZE ? PAGE_SIZE : inlen; }base-commit:
939cb14d51a150e3c12ef7a8ce0ba04ce6131bd2
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 41 lines · Trond Myklebust
Quoted 40 lines · On Mon, 2024-05-06 at 16:52 -0400, [email protected] wrote:
From: Chuck Lever <[email protected]>
Commit
5866efa8cbfb("SUNRPC: Fixsvcauth_gss_proxy_init()") from Oct 24, 2019 (linux-next), leads to the following Smatch static checker warning:net/sunrpc/auth_gss/svcauth_gss.c:1039
gss_free_in_token_pages()
warn: iterator 'i' not incremented
net/sunrpc/auth_gss/svcauth_gss.c
1034 static voidgss_free_in_token_pages(struct gssp_in_token *in_token)
1035 {
1036 u32 inlen;
1037 int i;
1038
--> 1039 i = 0;
1040 inlen =in_token->page_len;
1041 while (inlen) {
1042 if (in_token->pages[i])
1043put_page(in_token->pages[i]); ^ This puts page zero over and over.1044 inlen -= inlen >
PAGE_SIZE?PAGE_SIZE:
inlen;
1045 }
1046
1047kfree(in_token->pages);
1048in_token->pages= NULL;
1049 }Reported-by Dan Carpenter <[email protected]>Fixes 5866efa8cbfb ("SUNRPC: Fix svcauth_gss_proxy_init()")Signed-off-by Chuck Lever <[email protected]>---
net/sunrpc/auth_gss/svcauth_gss.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
net/sunrpc/auth_gss/svcauth_gss.c static void gss_free_in_token_pages(struct · line 1044
Quoted 12 lines
net/sunrpc/auth_gss/svcauth_gss.c +1
-1@@ -1040,7 +1040,7 @@ static void gss_free_in_token_pages(struct gssp_in_token *in_token) inlen = in_token->page_len; while (inlen) { if (in_token->pages[i]) -put_page (in_token->pages[i]); +put_page (in_token->pages[i++]);Wouldn't it be both more efficient and transparent just to break out of the loop once you hit a NULL page? You already know the remainder of the array will also be NULL.
Based on the way that the ->pages[] array is constructed in gss_read_proxy_verf() ? I guess that is true.
Quoted 5 lines
Quoted 5 lines
net/sunrpc/auth_gss/svcauth_gss.c +0
-0inlen -= inlen > PAGE_SIZE ? PAGE_SIZE : inlen; }base-commit:
939cb14d51a150e3c12ef7a8ce0ba04ce6131bd2
Signature · 1 line
Chuck Lever