Skip to contentSkip to conversation

afs: Fix overwriting of result of DNS query

PATCH In review David Howells 2 participants 3 messages Dec 21, 2023

Subsystems (2)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

PATCH 1/1 afs: Fix overwriting of result of DNS query

In afs_update_cell(), ret is the result of the DNS lookup and the errors are to be handled by a switch - however, the value gets clobbered in between by setting it to -ENOMEM in case afs_alloc_vlserver_list() fails.

Fix this by moving the setting of -ENOMEM into the error handling for OOM failure. Further, only do it if we don't have an alternative error to return.

Found by Linux Verification Center (linuxtesting.org) with SVACE. Based on a patch from Anastasia Belova[1].

Fixes d5c32c89b208 ("afs: Fix cell DNS lookup")
cc Anastasia Belova <[email protected]>
cc Marc Dionne <[email protected]>
---
 fs/afs/cell.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/afs/cell.c +4 -2
index 988c2ac7cece..926cb1188eba 100644
@@ -409,10 +409,12 @@ static int afs_update_cell(struct afs_cell *cell)
 		if (ret == -ENOMEM)
 			goto out_wake;
 
-		ret = -ENOMEM;
 		vllist = afs_alloc_vlserver_list(0);
-		if (!vllist)
+		if (!vllist) {
+			if (ret >= 0)
+				ret = -ENOMEM;
 			goto out_wake;
+		}
 
 		switch (ret) {
 		case -ENODATA:
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · David Howells

In afs_update_cell(), ret is the result of the DNS lookup and the errors are to be handled by a switch - however, the value gets clobbered in between by setting it to -ENOMEM in case afs_alloc_vlserver_list() fails.

Fix this by moving the setting of -ENOMEM into the error handling for OOM failure. Further, only do it if we don't have an alternative error to return.

Found by Linux Verification Center (linuxtesting.org) with SVACE. Based on a patch from Anastasia Belova[1].

Fixes d5c32c89b208 ("afs: Fix cell DNS lookup")
cc Anastasia Belova<[email protected]>
cc Marc Dionne<[email protected]>
---
  fs/afs/cell.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
fs/afs/cell.c +0 -1
index 988c2ac7cece..926cb1188eba 100644
@@ -409,10 +409,12 @@ static int afs_update_cell(struct afs_cell *cell)
  		if (ret == -ENOMEM)
  			goto out_wake;
 
-		ret = -ENOMEM;

fs/afs/cell.c static int afs_update_cell(struct afs_cell *cell) · line 420

Quoted 10 lines
fs/afs/cell.c +4 -1
  		vllist = afs_alloc_vlserver_list(0);
-		if (!vllist)
+		if (!vllist) {
+			if (ret >= 0)
+				ret = -ENOMEM;
  			goto out_wake;
+		}
 
  		switch (ret) {
  		case -ENODATA:
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Howells
Quoted 33 lines · David Howells

In afs_update_cell(), ret is the result of the DNS lookup and the errors are to be handled by a switch - however, the value gets clobbered in between by setting it to -ENOMEM in case afs_alloc_vlserver_list() fails.

Fix this by moving the setting of -ENOMEM into the error handling for OOM failure. Further, only do it if we don't have an alternative error to return.

Found by Linux Verification Center (linuxtesting.org) with SVACE. Based on a patch from Anastasia Belova[1].

Fixes d5c32c89b208 ("afs: Fix cell DNS lookup")
cc Anastasia Belova<[email protected]>
cc Marc Dionne<[email protected]>
---
  fs/afs/cell.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
fs/afs/cell.c +0 -1
index 988c2ac7cece..926cb1188eba 100644
@@ -409,10 +409,12 @@ static int afs_update_cell(struct afs_cell *cell)
  		if (ret == -ENOMEM)
  			goto out_wake;
 
-		ret = -ENOMEM;

fs/afs/cell.c static int afs_update_cell(struct afs_cell *cell) · line 420

Quoted 10 lines
fs/afs/cell.c +4 -1
  		vllist = afs_alloc_vlserver_list(0);
-		if (!vllist)
+		if (!vllist) {
+			if (ret >= 0)
+				ret = -ENOMEM;
  			goto out_wake;
+		}
 
  		switch (ret) {
  		case -ENODATA: