sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget&/translations/zh_CN/process/deprecatedmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/zh_TW/process/deprecatedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/it_IT/process/deprecatedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/ja_JP/process/deprecatedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/ko_KR/process/deprecatedmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/sp_SP/process/deprecatedmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh@/var/lib/git/docbuild/linux/Documentation/process/deprecated.rsthKubhtarget)}(h.. _deprecated:h]h}(h]h ]h"]h$]h&]refid deprecateduh1hhKhhhhhhubhsection)}(hhh](htitle)}(hEDeprecated Interfaces, Language Features, Attributes, and Conventionsh]hEDeprecated Interfaces, Language Features, Attributes, and Conventions}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hXIn a perfect world, it would be possible to convert all instances of some deprecated API into the new API and entirely remove the old API in a single development cycle. However, due to the size of the kernel, the maintainership hierarchy, and timing, it's not always feasible to do these kinds of conversions at once. This means that new instances may sneak into the kernel while old ones are being removed, only making the amount of work to remove the API grow. In order to educate developers about what has been deprecated and why, this list has been created as a place to point when uses of deprecated things are proposed for inclusion in the kernel.h]hXIn a perfect world, it would be possible to convert all instances of some deprecated API into the new API and entirely remove the old API in a single development cycle. However, due to the size of the kernel, the maintainership hierarchy, and timing, it’s not always feasible to do these kinds of conversions at once. This means that new instances may sneak into the kernel while old ones are being removed, only making the amount of work to remove the API grow. In order to educate developers about what has been deprecated and why, this list has been created as a place to point when uses of deprecated things are proposed for inclusion in the kernel.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hhh](h)}(h __deprecatedh]h __deprecated}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hXIWhile this attribute does visually mark an interface as deprecated, it `does not produce warnings during builds any more `_ because one of the standing goals of the kernel is to build without warnings and no one was actually doing anything to remove these deprecated interfaces. While using `__deprecated` is nice to note an old API in a header file, it isn't the full solution. Such interfaces must either be fully removed from the kernel, or added to this file to discourage others from using them in the future.h](hGWhile this attribute does visually mark an interface as deprecated, it }(hhhhhNhNubh reference)}(h{`does not produce warnings during builds any more `_h]h0does not produce warnings during builds any more}(hjhhhNhNubah}(h]h ]h"]h$]h&]name0does not produce warnings during builds any morerefuriEhttps://git.kernel.org/linus/771c035372a036f83353eef46dbb829780330234uh1jhhubh)}(hH h]h}(h]0does-not-produce-warnings-during-builds-any-moreah ]h"]0does not produce warnings during builds any moreah$]h&]refurijuh1h referencedKhhubh because one of the standing goals of the kernel is to build without warnings and no one was actually doing anything to remove these deprecated interfaces. While using }(hhhhhNhNubhtitle_reference)}(h`__deprecated`h]h __deprecated}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j&hhubh is nice to note an old API in a header file, it isn’t the full solution. Such interfaces must either be fully removed from the kernel, or added to this file to discourage others from using them in the future.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h]id1ah ]h"] __deprecatedah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hBUG() and BUG_ON()h]hBUG() and BUG_ON()}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjHhhhhhK!ubh)}(hXUse WARN() and WARN_ON() instead, and handle the "impossible" error condition as gracefully as possible. While the BUG()-family of APIs were originally designed to act as an "impossible situation" assert and to kill a kernel thread "safely", they turn out to just be too risky. (e.g. "In what order do locks need to be released? Have various states been restored?") Very commonly, using BUG() will destabilize a system or entirely break it, which makes it impossible to debug or even get viable crash reports. Linus has `very strong `_ feelings `about this `_.h](hXUse WARN() and WARN_ON() instead, and handle the “impossible” error condition as gracefully as possible. While the BUG()-family of APIs were originally designed to act as an “impossible situation” assert and to kill a kernel thread “safely”, they turn out to just be too risky. (e.g. “In what order do locks need to be released? Have various states been restored?”) Very commonly, using BUG() will destabilize a system or entirely break it, which makes it impossible to debug or even get viable crash reports. Linus has }(hjYhhhNhNubj)}(hq`very strong `_h]h very strong}(hjahhhNhNubah}(h]h ]h"]h$]h&]name very strongj`https://lore.kernel.org/lkml/CA+55aFy6jNLsywVYdGp83AMrXBo_P-pkjkphPGrO=82SPKCpLQ@mail.gmail.com/uh1jhjYubh)}(hc h]h}(h] very-strongah ]h"] very strongah$]h&]refurijquh1hj!KhjYubh feelings }(hjYhhhNhNubj)}(hp`about this `_h]h about this}(hjhhhNhNubah}(h]h ]h"]h$]h&]name about thisj`https://lore.kernel.org/lkml/CAHk-=whDHsbK3HTOpTF=ue_o04onRwTEaK_ZoJp_fjbqq4+=Jw@mail.gmail.com/uh1jhjYubh)}(hc h]h}(h] about-thisah ]h"] about thisah$]h&]refurijuh1hj!KhjYubh.}(hjYhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK"hjHhhubh)}(hXNote that the WARN()-family should only be used for "expected to be unreachable" situations. If you want to warn about "reachable but undesirable" situations, please use the pr_warn()-family of functions. System owners may have set the *panic_on_warn* sysctl, to make sure their systems do not continue running in the face of "unreachable" conditions. (For example, see commits like `this one `_.)h](hNote that the WARN()-family should only be used for “expected to be unreachable” situations. If you want to warn about “reachable but undesirable” situations, please use the pr_warn()-family of functions. System owners may have set the }(hjhhhNhNubhemphasis)}(h*panic_on_warn*h]h panic_on_warn}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh sysctl, to make sure their systems do not continue running in the face of “unreachable” conditions. (For example, see commits like }(hjhhhNhNubj)}(hS`this one `_h]hthis one}(hjhhhNhNubah}(h]h ]h"]h$]h&]namethis onejEhttps://git.kernel.org/linus/d4689846881d160a4d12a514e991a740bcb5d65auh1jhjubh)}(hH h]h}(h]this-oneah ]h"]this oneah$]h&]refurijuh1hj!Khjubh.)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK.hjHhhubeh}(h]bug-and-bug-onah ]h"]bug() and bug_on()ah$]h&]uh1hhhhhhhhK!ubh)}(hhh](h)}(h,open-coded arithmetic in allocator argumentsh]h,open-coded arithmetic in allocator arguments}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK7ubh)}(hXHDynamic size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. (One exception to this is literal values where the compiler can warn if they might overflow. However, the preferred way in these cases is to refactor the code as suggested below to avoid the open-coded arithmetic.)h]hXHDynamic size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. (One exception to this is literal values where the compiler can warn if they might overflow. However, the preferred way in these cases is to refactor the code as suggested below to avoid the open-coded arithmetic.)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK8hjhhubh)}(h@For example, do not use ``count * size`` as an argument, as in::h](hFor example, do not use }(hjhhhNhNubhliteral)}(h``count * size``h]h count * size}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh as an argument, as in:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKBhjhhubh literal_block)}(h(foo = kmalloc(count * size, GFP_KERNEL);h]h(foo = kmalloc(count * size, GFP_KERNEL);}hj:sbah}(h]h ]h"]h$]h&]hhuh1j8hhhKDhjhhubh)}(hitem), GFP_KERNEL);h]h_header = kzalloc(sizeof(*header) + count * sizeof(*header->item), GFP_KERNEL);}hjsbah}(h]h ]h"]h$]h&]hhuh1j8hhhKUhjhhubh)}(hInstead, use the helper::h]hInstead, use the helper:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhjhhubj9)}(h?header = kzalloc(struct_size(header, item, count), GFP_KERNEL);h]h?header = kzalloc(struct_size(header, item, count), GFP_KERNEL);}hjsbah}(h]h ]h"]h$]h&]hhuh1j8hhhKZhjhhubhnote)}(hIf you are using struct_size() on a structure containing a zero-length or a one-element array as a trailing array member, please refactor such array usage and switch to a `flexible array member <#zero-length-and-one-element-arrays>`_ instead.h]h)}(hIf you are using struct_size() on a structure containing a zero-length or a one-element array as a trailing array member, please refactor such array usage and switch to a `flexible array member <#zero-length-and-one-element-arrays>`_ instead.h](hIf you are using struct_size() on a structure containing a zero-length or a one-element array as a trailing array member, please refactor such array usage and switch to a }(hjhhhNhNubj)}(h>`flexible array member <#zero-length-and-one-element-arrays>`_h]hflexible array member}(hjhhhNhNubah}(h]h ]h"]h$]h&]nameflexible array memberj##zero-length-and-one-element-arraysuh1jhjubh)}(h& <#zero-length-and-one-element-arrays>h]h}(h]flexible-array-memberah ]h"]flexible array memberah$]h&]refurijuh1hj!Khjubh instead.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK\hjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubh)}(hFor other calculations, please compose the use of the size_mul(), size_add(), and size_sub() helpers. For example, in the case of::h]hFor other calculations, please compose the use of the size_mul(), size_add(), and size_sub() helpers. For example, in the case of:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKahjhhubj9)}(hDfoo = krealloc(current_size + chunk_size * (count - 3), GFP_KERNEL);h]hDfoo = krealloc(current_size + chunk_size * (count - 3), GFP_KERNEL);}hjsbah}(h]h ]h"]h$]h&]hhuh1j8hhhKdhjhhubh)}(hInstead, use the helpers::h]hInstead, use the helpers:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKfhjhhubj9)}(hfoo = krealloc(size_add(current_size, size_mul(chunk_size, size_sub(count, 3))), GFP_KERNEL);h]hfoo = krealloc(size_add(current_size, size_mul(chunk_size, size_sub(count, 3))), GFP_KERNEL);}hj,sbah}(h]h ]h"]h$]h&]hhuh1j8hhhKhhjhhubh)}(hFor more details, also see array3_size() and flex_array_size(), as well as the related check_mul_overflow(), check_add_overflow(), check_sub_overflow(), and check_shl_overflow() family of functions.h]hFor more details, also see array3_size() and flex_array_size(), as well as the related check_mul_overflow(), check_add_overflow(), check_sub_overflow(), and check_shl_overflow() family of functions.}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKlhjhhubeh}(h],open-coded-arithmetic-in-allocator-argumentsah ]h"],open-coded arithmetic in allocator argumentsah$]h&]uh1hhhhhhhhK7ubh)}(hhh](h)}(hFsimple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull()h]hFsimple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull()}(hjShhhNhNubah}(h]h ]h"]h$]h&]uh1hhjPhhhhhKqubh)}(hXbThe simple_strtol(), simple_strtoll(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers. The respective kstrtol(), kstrtoll(), kstrtoul(), and kstrtoull() functions tend to be the correct replacements, though note that those require the string to be NUL or newline terminated.h]hXbThe simple_strtol(), simple_strtoll(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers. The respective kstrtol(), kstrtoll(), kstrtoul(), and kstrtoull() functions tend to be the correct replacements, though note that those require the string to be NUL or newline terminated.}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKrhjPhhubeh}(h];simple-strtol-simple-strtoll-simple-strtoul-simple-strtoullah ]h"]Fsimple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull()ah$]h&]uh1hhhhhhhhKqubh)}(hhh](h)}(hstrcpy()h]hstrcpy()}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjwhhhhhK{ubh)}(hXRstrcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors. While `CONFIG_FORTIFY_SOURCE=y` and various compiler flags help reduce the risk of using this function, there is no good reason to add new uses of this function. The safe replacement is strscpy(), though care must be given to any cases where the return value of strcpy() was used, since strscpy() does not return a pointer to the destination, but rather a count of non-NUL bytes copied (or negative errno when it truncates).h](hstrcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors. While }(hjhhhNhNubj')}(h`CONFIG_FORTIFY_SOURCE=y`h]hCONFIG_FORTIFY_SOURCE=y}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j&hjubhX and various compiler flags help reduce the risk of using this function, there is no good reason to add new uses of this function. The safe replacement is strscpy(), though care must be given to any cases where the return value of strcpy() was used, since strscpy() does not return a pointer to the destination, but rather a count of non-NUL bytes copied (or negative errno when it truncates).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK|hjwhhubeh}(h]strcpyah ]h"]strcpy()ah$]h&]uh1hhhhhhhhK{ubh)}(hhh](h)}(h#strncpy() on NUL-terminated stringsh]h#strncpy() on NUL-terminated strings}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXUse of strncpy() does not guarantee that the destination buffer will be NUL terminated. This can lead to various linear read overflows and other misbehavior due to the missing termination. It also NUL-pads the destination buffer if the source contents are shorter than the destination buffer size, which may be a needless performance penalty for callers using only NUL-terminated strings.h]hXUse of strncpy() does not guarantee that the destination buffer will be NUL terminated. This can lead to various linear read overflows and other misbehavior due to the missing termination. It also NUL-pads the destination buffer if the source contents are shorter than the destination buffer size, which may be a needless performance penalty for callers using only NUL-terminated strings.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXWhen the destination is required to be NUL-terminated, the replacement is strscpy(), though care must be given to any cases where the return value of strncpy() was used, since strscpy() does not return a pointer to the destination, but rather a count of non-NUL bytes copied (or negative errno when it truncates). Any cases still needing NUL-padding should instead use strscpy_pad().h]hXWhen the destination is required to be NUL-terminated, the replacement is strscpy(), though care must be given to any cases where the return value of strncpy() was used, since strscpy() does not return a pointer to the destination, but rather a count of non-NUL bytes copied (or negative errno when it truncates). Any cases still needing NUL-padding should instead use strscpy_pad().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hX<If a caller is using non-NUL-terminated strings, strtomem() should be used, and the destinations should be marked with the `__nonstring `_ attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used.h](h{If a caller is using non-NUL-terminated strings, strtomem() should be used, and the destinations should be marked with the }(hjhhhNhNubj)}(hS`__nonstring `_h]h __nonstring}(hjhhhNhNubah}(h]h ]h"]h$]h&]name __nonstringjBhttps://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.htmluh1jhjubh)}(hE h]h}(h] nonstringah ]h"] __nonstringah$]h&]refurijuh1hj!Khjubhn attribute to avoid future compiler warnings. For cases still needing NUL-padding, strtomem_pad() can be used.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]!strncpy-on-nul-terminated-stringsah ]h"]#strncpy() on nul-terminated stringsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h strlcpy()h]h strlcpy()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hXstrlcpy() reads the entire source buffer first (since the return value is meant to match that of strlen()). This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated. The safe replacement is strscpy(), though care must be given to any cases where the return value of strlcpy() is used, since strscpy() will return negative errno values when it truncates.h]hXstrlcpy() reads the entire source buffer first (since the return value is meant to match that of strlen()). This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated. The safe replacement is strscpy(), though care must be given to any cases where the return value of strlcpy() is used, since strscpy() will return negative errno values when it truncates.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]strlcpyah ]h"] strlcpy()ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h%p format specifierh]h%p format specifier}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj<hhhhhKubh)}(hXTraditionally, using "%p" in format strings would lead to regular address exposure flaws in dmesg, proc, sysfs, etc. Instead of leaving these to be exploitable, all "%p" uses in the kernel are being printed as a hashed value, rendering them unusable for addressing. New uses of "%p" should not be added to the kernel. For text addresses, using "%pS" is likely better, as it produces the more useful symbol name instead. For nearly everything else, just do not add "%p" at all.h]hXTraditionally, using “%p” in format strings would lead to regular address exposure flaws in dmesg, proc, sysfs, etc. Instead of leaving these to be exploitable, all “%p” uses in the kernel are being printed as a hashed value, rendering them unusable for addressing. New uses of “%p” should not be added to the kernel. For text addresses, using “%pS” is likely better, as it produces the more useful symbol name instead. For nearly everything else, just do not add “%p” at all.}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj<hhubh)}(hParaphrasing Linus's current `guidance `_:h](hParaphrasing Linus’s current }(hj[hhhNhNubj)}(hn`guidance `_h]hguidance}(hjchhhNhNubah}(h]h ]h"]h$]h&]nameguidancej`https://lore.kernel.org/lkml/CA+55aFwQEd_d40g4mUCSsVRZzrFPUJt74vc6PPpb675hYNXcKw@mail.gmail.com/uh1jhj[ubh)}(hc h]h}(h]guidanceah ]h"]guidanceah$]h&]refurijsuh1hj!Khj[ubh:}(hj[hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj<hhubh bullet_list)}(hhh](h list_item)}(hIf the hashed "%p" value is pointless, ask yourself whether the pointer itself is important. Maybe it should be removed entirely?h]h)}(hIf the hashed "%p" value is pointless, ask yourself whether the pointer itself is important. Maybe it should be removed entirely?h]hIf the hashed “%p” value is pointless, ask yourself whether the pointer itself is important. Maybe it should be removed entirely?}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hX9If you really think the true pointer value is important, why is some system state or user privilege level considered "special"? If you think you can justify it (in comments and commit log) well enough to stand up to Linus's scrutiny, maybe you can use "%px", along with making sure you have sensible permissions. h]h)}(hX8If you really think the true pointer value is important, why is some system state or user privilege level considered "special"? If you think you can justify it (in comments and commit log) well enough to stand up to Linus's scrutiny, maybe you can use "%px", along with making sure you have sensible permissions.h]hXBIf you really think the true pointer value is important, why is some system state or user privilege level considered “special”? If you think you can justify it (in comments and commit log) well enough to stand up to Linus’s scrutiny, maybe you can use “%px”, along with making sure you have sensible permissions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1jhhhKhj<hhubh)}(hIf you are debugging something where "%p" hashing is causing problems, you can temporarily boot with the debug flag "`no_hash_pointers `_".h](h{If you are debugging something where “%p” hashing is causing problems, you can temporarily boot with the debug flag “}(hjhhhNhNubj)}(h[`no_hash_pointers `_h]hno_hash_pointers}(hjhhhNhNubah}(h]h ]h"]h$]h&]nameno_hash_pointersjEhttps://git.kernel.org/linus/5ead723a20e0447bc7db33dc3070b420e5f80aa6uh1jhjubh)}(hH h]h}(h]no-hash-pointersah ]h"]no_hash_pointersah$]h&]refurijuh1hj!Khjubh”.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj<hhubeh}(h]p-format-specifierah ]h"]%p format specifierah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hVariable Length Arrays (VLAs)h]hVariable Length Arrays (VLAs)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hX1Using stack VLAs produces much worse machine code than statically sized stack arrays. While these non-trivial `performance issues `_ are reason enough to eliminate VLAs, they are also a security risk. Dynamic growth of a stack array may exceed the remaining memory in the stack segment. This could lead to a crash, possible overwriting sensitive contents at the end of the stack (when built without `CONFIG_THREAD_INFO_IN_TASK=y`), or overwriting memory adjacent to the stack (when built without `CONFIG_VMAP_STACK=y`)h](hnUsing stack VLAs produces much worse machine code than statically sized stack arrays. While these non-trivial }(hjhhhNhNubj)}(hA`performance issues `_h]hperformance issues}(hjhhhNhNubah}(h]h ]h"]h$]h&]nameperformance issuesj)https://git.kernel.org/linus/02361bc77888uh1jhjubh)}(h, h]h}(h]performance-issuesah ]h"]performance issuesah$]h&]refurij+uh1hj!KhjubhX  are reason enough to eliminate VLAs, they are also a security risk. Dynamic growth of a stack array may exceed the remaining memory in the stack segment. This could lead to a crash, possible overwriting sensitive contents at the end of the stack (when built without }(hjhhhNhNubj')}(h`CONFIG_THREAD_INFO_IN_TASK=y`h]hCONFIG_THREAD_INFO_IN_TASK=y}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1j&hjubhC), or overwriting memory adjacent to the stack (when built without }(hjhhhNhNubj')}(h`CONFIG_VMAP_STACK=y`h]hCONFIG_VMAP_STACK=y}(hjOhhhNhNubah}(h]h ]h"]h$]h&]uh1j&hjubh)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]variable-length-arrays-vlasah ]h"]variable length arrays (vlas)ah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h!Implicit switch case fall-throughh]h!Implicit switch case fall-through}(hjrhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjohhhhhKubh)}(hX}The C language allows switch cases to fall through to the next case when a "break" statement is missing at the end of a case. This, however, introduces ambiguity in the code, as it's not always clear if the missing break is intentional or a bug. For example, it's not obvious just from looking at the code if `STATE_ONE` is intentionally designed to fall through into `STATE_TWO`::h](hX=The C language allows switch cases to fall through to the next case when a “break” statement is missing at the end of a case. This, however, introduces ambiguity in the code, as it’s not always clear if the missing break is intentional or a bug. For example, it’s not obvious just from looking at the code if }(hjhhhNhNubj')}(h `STATE_ONE`h]h STATE_ONE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j&hjubh0 is intentionally designed to fall through into }(hjhhhNhNubj')}(h `STATE_TWO`h]h STATE_TWO}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j&hjubh:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjohhubj9)}(hswitch (value) { case STATE_ONE: do_something(); case STATE_TWO: do_other(); break; default: WARN("unknown state"); }h]hswitch (value) { case STATE_ONE: do_something(); case STATE_TWO: do_other(); break; default: WARN("unknown state"); }}hjsbah}(h]h ]h"]h$]h&]hhuh1j8hhhKhjohhubh)}(hXMAs there have been a long list of flaws `due to missing "break" statements `_, we no longer allow implicit fall-through. In order to identify intentional fall-through cases, we have adopted a pseudo-keyword macro "fallthrough" which expands to gcc's extension `__attribute__((__fallthrough__)) `_. (When the C17/C18 `[[fallthrough]]` syntax is more commonly supported by C compilers, static analyzers, and IDEs, we can switch to using that syntax for the macro pseudo-keyword.)h](h(As there have been a long list of flaws }(hjhhhNhNubj)}(hV`due to missing "break" statements `_h]h%due to missing “break” statements}(hjhhhNhNubah}(h]h ]h"]h$]h&]name!due to missing "break" statementsj/https://cwe.mitre.org/data/definitions/484.htmluh1jhjubh)}(h2 h]h}(h]due-to-missing-break-statementsah ]h"]!due to missing "break" statementsah$]h&]refurijuh1hj!Khjubh, we no longer allow implicit fall-through. In order to identify intentional fall-through cases, we have adopted a pseudo-keyword macro “fallthrough” which expands to gcc’s extension }(hjhhhNhNubj)}(hb`__attribute__((__fallthrough__)) `_h]h __attribute__((__fallthrough__))}(hjhhhNhNubah}(h]h ]h"]h$]h&]name __attribute__((__fallthrough__))jh]h}(h]attribute-fallthroughah ]h"] __attribute__((__fallthrough__))ah$]h&]refurijuh1hj!Khjubh. (When the C17/C18 }(hjhhhNhNubj')}(h`[[fallthrough]]`h]h[[fallthrough]]}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j&hjubh syntax is more commonly supported by C compilers, static analyzers, and IDEs, we can switch to using that syntax for the macro pseudo-keyword.)}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjohhubh)}(h*All switch/case blocks must end in one of:h]h*All switch/case blocks must end in one of:}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjohhubj)}(hhh](j)}(hbreak;h]h)}(hj7h]hbreak;}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj5ubah}(h]h ]h"]h$]h&]uh1jhj2hhhhhNubj)}(h fallthrough;h]h)}(hjNh]h fallthrough;}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjLubah}(h]h ]h"]h$]h&]uh1jhj2hhhhhNubj)}(h continue;h]h)}(hjeh]h continue;}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjcubah}(h]h ]h"]h$]h&]uh1jhj2hhhhhNubj)}(h goto