]> git.dujemihanovic.xyz Git - linux.git/commitdiff
afs: Fix overwriting of result of DNS query
authorDavid Howells <dhowells@redhat.com>
Thu, 21 Dec 2023 15:09:31 +0000 (15:09 +0000)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 21 Dec 2023 17:57:43 +0000 (09:57 -0800)
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")
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeffrey Altman <jaltman@auristor.com>
cc: Anastasia Belova <abelova@astralinux.ru>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: lvc-project@linuxtesting.org
Link: https://lore.kernel.org/r/20231221085849.1463-1-abelova@astralinux.ru/
Link: https://lore.kernel.org/r/1700862.1703168632@warthog.procyon.org.uk/
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/afs/cell.c

index 988c2ac7cececdfdf946eedc0f49c79533e76e99..926cb1188eba6c484a345b6e27fecfff48e4f3f9 100644 (file)
@@ -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: