| From: Arnd Bergmann <arnd@arndb.de> |
| Subject: mm, cma: use literal printf format string |
| Date: Mon, 24 Feb 2025 15:07:36 +0100 |
| |
| Using a variable string as a printf format can be a security issue that |
| clang warns about when extra warnings are enabled: |
| |
| mm/cma.c:239:37: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security] |
| 239 | snprintf(cma->name, CMA_MAX_NAME, name); |
| | ^~~~ |
| |
| This one does not appear to be a security issue since the string is |
| not user controlled, but it's better to avoid the warning. |
| Use "%s" as the format instead and just pass the name as the argument. |
| |
| Link: https://lkml.kernel.org/r/20250224141120.1240534-2-arnd@kernel.org |
| Signed-off-by: Arnd Bergmann <arnd@arndb.de> |
| Reviewed-by: Zi Yan <ziy@nvidia.com> |
| Acked-by: David Hildenbrand <david@redhat.com> |
| Reviewed-by: Frank van der Linden <fvdl@google.com> |
| Signed-off-by: Andrew Morton <akpm@linux-foundation.org> |
| --- |
| |
| mm/cma.c | 2 +- |
| 1 file changed, 1 insertion(+), 1 deletion(-) |
| |
| --- a/mm/cma.c~mm-cma-support-multiple-contiguous-ranges-if-requested-fix-2 |
| +++ a/mm/cma.c |
| @@ -199,7 +199,7 @@ static int __init cma_new_area(const cha |
| cma_area_count++; |
| |
| if (name) |
| - snprintf(cma->name, CMA_MAX_NAME, name); |
| + snprintf(cma->name, CMA_MAX_NAME, "%s", name); |
| else |
| snprintf(cma->name, CMA_MAX_NAME, "cma%d\n", cma_area_count); |
| |
| _ |