Close Menu

    Subscribe to Updates

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

    What's Hot

    Future of Marketing Briefing: AI confuses marketers but their own uncertainty runs deeper

    European publishers say the Digital Omnibus ‘cookie fix’ leaves them worse off

    Ulta, Best Buy and Adidas dominate AI holiday shopping mentions

    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

      HBAR Price Enters Consolidation As Hedera Pulls Away From Bitcoin

      December 5, 2025

      Why Chinese Investors Don’t Welcome Dollar Stablecoins Any More

      December 5, 2025

      Bitcoin Exchange Supply Nears 5-year Low After $2 Billion Buy This Week

      December 5, 2025

      Over $4 Billion in BTC and ETH Options Vanish as Traders Quietly Bet on a 2026 Comeback

      December 5, 2025

      US Opens Door to Leveraged Spot Crypto Trading, a First Under Federal Regulation

      December 5, 2025
    • Technology

      Future of Marketing Briefing: AI confuses marketers but their own uncertainty runs deeper

      December 5, 2025

      European publishers say the Digital Omnibus ‘cookie fix’ leaves them worse off

      December 5, 2025

      Ulta, Best Buy and Adidas dominate AI holiday shopping mentions

      December 5, 2025

      In Graphic Detail: Here’s what the creator economy is expected to look like in 2026

      December 5, 2025

      From trust to turbulence: Cyber’s road ahead in 2026

      December 5, 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

    Future of Marketing Briefing: AI confuses marketers but their own uncertainty runs deeper

    December 5, 2025

    European publishers say the Digital Omnibus ‘cookie fix’ leaves them worse off

    December 5, 2025

    Ulta, Best Buy and Adidas dominate AI holiday shopping mentions

    December 5, 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, 2025480 Views

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

    July 31, 2025162 Views

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

    April 14, 202586 Views

    Is Libby Compatible With Kobo E-Readers?

    March 31, 202563 Views
    Don't Miss
    Technology December 5, 2025

    Future of Marketing Briefing: AI confuses marketers but their own uncertainty runs deeper

    Future of Marketing Briefing: AI confuses marketers but their own uncertainty runs deeperThis Future of…

    European publishers say the Digital Omnibus ‘cookie fix’ leaves them worse off

    Ulta, Best Buy and Adidas dominate AI holiday shopping mentions

    In Graphic Detail: Here’s what the creator economy is expected to look like in 2026

    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

    Future of Marketing Briefing: AI confuses marketers but their own uncertainty runs deeper

    December 5, 20250 Views

    European publishers say the Digital Omnibus ‘cookie fix’ leaves them worse off

    December 5, 20250 Views

    Ulta, Best Buy and Adidas dominate AI holiday shopping mentions

    December 5, 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.