From 74ba5b5401a7fe768fbfb71423ca78fb68ba2157 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 13 Jun 2022 14:20:06 +0200 Subject: [PATCH] virNetDevSaveNetConfig: Pass mode to virFileWriteStr() For some types of SRIOV interfaces we create a temporary file where the state of the interface is saved before we start modifying it. The file is used then to restore the original configuration when the interface is no longer associated with any guest. For writing the file virFileWriteStr() is used. However, it's given wrong argument: the last argument is supposed to be mode to create the file with but virNetDevSaveNetConfig() passes open(2) flags (O_CREAT|O_TRUNC|O_WRONLY). We need the file to be writable and readable by root only (0600). Therefore, pass that mode instead of gibberish. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/util/virnetdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 93f836cd92..6c6f6dee42 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -1977,7 +1977,7 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, if (!(fileStr = virJSONValueToString(configJSON, true))) return -1; - if (virFileWriteStr(filePath, fileStr, O_CREAT|O_TRUNC|O_WRONLY) < 0) { + if (virFileWriteStr(filePath, fileStr, 0600) < 0) { virReportSystemError(errno, _("Unable to preserve mac/vlan tag " "for device = %s, vf = %d"), linkdev, vf); return -1; -- 2.47.2