Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Pikmin Bloom has topped $100 million in lifetime player spend since launch

    British retro gaming journalist Nick Thorpe has died unexpectedly aged 38

    Tencent halts Light of Motiram testing and marketing as Horizon copyright lawsuit date set for January

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Apple’s AI chief abruptly steps down

      December 3, 2025

      The issue that’s scrambling both parties: From the Politics Desk

      December 3, 2025

      More of Silicon Valley is building on free Chinese AI

      December 1, 2025

      From Steve Bannon to Elizabeth Warren, backlash erupts over push to block states from regulating AI

      November 23, 2025

      Insurance companies are trying to avoid big payouts by making AI safer

      November 19, 2025
    • Business

      Public GitLab repositories exposed more than 17,000 secrets

      November 29, 2025

      ASUS warns of new critical auth bypass flaw in AiCloud routers

      November 28, 2025

      Windows 11 gets new Cloud Rebuild, Point-in-Time Restore tools

      November 18, 2025

      Government faces questions about why US AWS outage disrupted UK tax office and banking firms

      October 23, 2025

      Amazon’s AWS outage knocked services like Alexa, Snapchat, Fortnite, Venmo and more offline

      October 21, 2025
    • Crypto

      Most Bitcoin On-Chain Indicators Signal a New Bear Market Cycle

      December 3, 2025

      Why the Latest Binance Lawsuit Is More Dangerous Than Any Regulator

      December 3, 2025

      Could the Fusaka Upgrade Light the Fuse for a Pectra-Like 56% Ethereum Price Rally?

      December 3, 2025

      Bitcoin Mining Hit Its Breaking Point — Now AI Is Taking Over Its Racks | US Crypto News

      December 3, 2025

      XRP Jumps 8% as Crypto Whales Scoop Up $1.3 Billion 

      December 3, 2025
    • Technology

      Tariff turbulence exposes costly blind spots in supply chains and AI

      December 3, 2025

      AI has redefined the talent game. Here’s how leaders are responding.

      December 3, 2025

      Workspace Studio aims to solve the real agent problem: Getting employees to use them

      December 3, 2025

      Interview: Florence Mottay, global CISO, Zalando

      December 3, 2025

      In 2026, collaboration, honesty and humility in cyber are key

      December 3, 2025
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Checked-size array parameters in C
    Technology

    Checked-size array parameters in C

    TechAiVerseBy TechAiVerseDecember 3, 2025No Comments5 Mins Read0 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Checked-size array parameters in C
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Checked-size array parameters in C

    Welcome to LWN.net

    The following subscription-only content has been made available to you
    by an LWN subscriber. Thousands of subscribers depend on LWN for the
    best news from the Linux and free software communities. If you enjoy this
    article, please consider subscribing to LWN. Thank you
    for visiting LWN.net!

    By Jonathan Corbet
    December 1, 2025

    There are many possible programmer mistakes that are not caught by the
    minimal checks specified by the C language; among those is passing an array
    of the wrong size to a function. A recent attempt to add some safety
    around array parameters within the crypto layer involved the use of some
    clever tricks, but it turns out that clever tricks are unnecessary in this
    case. There is an obscure C feature that can cause this checking to
    happen, and it is already in use in a few places within the kernel.

    The discussion started when Ard Biesheuvel sought to
    improve the safety of the poetically named function
    xchacha20poly1305_encrypt():

        void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
    			           const u8 *ad, const size_t ad_len,
    			       	   const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE],
    			       	   const u8 key[CHACHA20POLY1305_KEY_SIZE]);
    

    A potential problem with this function is that it takes as parameters
    several pointers to arrays of type u8. As Biesheuvel pointed out,
    the size of the nonce and key arrays is not checked by
    the compiler, even though it is clearly specified in the function
    prototype. That makes it easy to, for example, give the parameters in the
    wrong order. The resulting vulnerabilities are generally not the outcome
    developers have in mind when they write cryptographic code.

    Biesheuvel suggested that it was possible to write the prototype this way
    instead (differences shown in bold):

        void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
    			           const u8 *ad, const size_t ad_len,
    			       	   const u8 (*nonce)[XCHACHA20POLY1305_NONCE_SIZE],
    			       	   const u8 (*key)[CHACHA20POLY1305_KEY_SIZE]);
    

    The types of the last two arguments have changed; there is a new level of
    pointer indirection, with the argument being a pointer to an array of a
    given size. Callers must change their calls by adding an additional
    & operator to obtain the desired pointer type, but the address
    that is passed is the same. In this case, though, the compiler will check
    the sizes of the array passed, and will now catch a reordering of the
    arguments to the function.

    Jason Donenfeld was
    interested
    by the idea, but he knew of an arguably more straightforward
    way to address this problem. It seems that, buried deep within the C
    standard, is a strange usage of the static keyword, making it
    possible to write the prototype as:

        void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
    			           const u8 *ad, const size_t ad_len,
    			       	   const u8 nonce[static XCHACHA20POLY1305_NONCE_SIZE],
    			       	   const u8 key[static CHACHA20POLY1305_KEY_SIZE]);
    

    This, too, will cause the compiler to check the sizes of the arrays, and it
    does not require changes on the caller side. Unlike the pointer trick,
    which requires an exact match on the array size, use of static
    will only generate a warning if the passed-in array is too small. So it
    will not catch all mistakes, though it is sufficient to prevent
    memory-safety and swapped-argument problems.

    Eric Biggers pointed out
    that GCC can often generate “array too small” warnings even without
    static, but that the kernel currently disables those warnings;
    that would suppress them when static is used as well. (The
    warning was disabled in
    6.8
    due to false positives.) But he thought that adding
    static was worthwhile to get the warnings in Clang — if Linus
    Torvalds would be willing to accept use of “this relatively obscure
    feature of C
    “.

    Torvalds, as it turns out, has
    no objection
    to this usage; he likes the feature, if not the way it was
    designed:

    The main issue with the whole ‘static’ thing is just that the
    syntax is such a horrible hack, where people obviously picked an
    existing keyword that made absolutely no sense, but was also
    guaranteed to have no backwards compatibility issues.

    He pointed out that there are a number of places in the kernel that are
    already using it; for a simple example, see getconsxy()
    in the virtual-terminal driver. He suggested perhaps hiding it with a
    macro like min_array_size() just to make the usage more obvious,
    but didn’t seem convinced that it was necessary. Donenfeld followed up with
    a patch to that effect a few days later, but then pivoted to an
    at_least marker
    instead.

    A lot of work has gone into the kernel to make its use of C as safe as
    possible, but that does not mean that the low-hanging fruit has all been
    picked. The language has features, such as static when used to
    define formal array parameters, that can improve safety, but which are not
    generally known and not often used. In this particular case, though, it
    would not be surprising to see this “horrible hack” come into wider
    use in the near future.

    Index entries for this article
    Kernel C language safety
    Kernel Releases/6.19




    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleShow HN: I built a dashboard to compare mortgage rates across 120 credit unions
    Next Article Agentic Development Environment by JetBrains
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Tariff turbulence exposes costly blind spots in supply chains and AI

    December 3, 2025

    AI has redefined the talent game. Here’s how leaders are responding.

    December 3, 2025

    Workspace Studio aims to solve the real agent problem: Getting employees to use them

    December 3, 2025
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025471 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025160 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 202584 Views

    Is Libby Compatible With Kobo E-Readers?

    March 31, 202563 Views
    Don't Miss
    Gaming December 4, 2025

    Pikmin Bloom has topped $100 million in lifetime player spend since launch

    Pikmin Bloom has topped $100 million in lifetime player spend since launch 2025 is the…

    British retro gaming journalist Nick Thorpe has died unexpectedly aged 38

    Tencent halts Light of Motiram testing and marketing as Horizon copyright lawsuit date set for January

    EA makes eight new accessibility patents free to all

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Pikmin Bloom has topped $100 million in lifetime player spend since launch

    December 4, 20250 Views

    British retro gaming journalist Nick Thorpe has died unexpectedly aged 38

    December 4, 20250 Views

    Tencent halts Light of Motiram testing and marketing as Horizon copyright lawsuit date set for January

    December 4, 20250 Views
    Most Popular

    Apple thinks people won’t use MagSafe on iPhone 16e

    March 12, 20250 Views

    Volkswagen’s cheapest EV ever is the first to use Rivian software

    March 12, 20250 Views

    Startup studio Hexa acquires majority stake in Veevart, a vertical SaaS platform for museums

    March 12, 20250 Views
    © 2025 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.