It can be dangerous and there is no need for it in the kernel. Inspired by Kees Cook's change in Linux, and later OpenBSD.
Details
Details
- Reviewers
cem philip gordon - Group Reviewers
manpages - Commits
- rS360849: remove %n support from printf(9)
Diff Detail
Diff Detail
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
Comment Actions
I double-checked @emaste's grep and likewise see no consumer of %n in callers of kernel printf(9).
Comment Actions
Looks good to me. I haven't tested it, but seeing as it is the same patch as OpenBSD's it should do what is expected.
Comment Actions
I think this should do it:
--- a/contrib/llvm-project/clang/lib/AST/PrintfFormatString.cpp +++ b/contrib/llvm-project/clang/lib/AST/PrintfFormatString.cpp @@ -316,8 +316,8 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H, case 'g': k = ConversionSpecifier::gArg; break; case 'i': k = ConversionSpecifier::iArg; break; case 'n': - // Not handled, but reserved in OpenCL. - if (!LO.OpenCL) + // Not handled, but reserved in OpenCL and FreeBSD kernel. + if (!LO.OpenCL && !isFreeBSDKPrintf) k = ConversionSpecifier::nArg; break; case 'o': k = ConversionSpecifier::oArg; break;