From nobody Fri Sep 03 17:45:41 2021 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7FA4E17B63D6 for ; Fri, 3 Sep 2021 17:46:00 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H1QFN2jThz3vFb for ; Fri, 3 Sep 2021 17:46:00 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: by mail-pj1-x102d.google.com with SMTP id fz10so100942pjb.0 for ; Fri, 03 Sep 2021 10:46:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Yw6fD9J4ML7PJDF5kBvosPIyEo8IsJ1SsMGunTYr7bQ=; b=bINwjFMqJC7/rFwfVTjWQQumjYzWL4nxI2Ygw6to7BsXmXmxSOn2SMqTVK1J2B7I1w PN/4zuyc4yj1pHJcrljiQsXYjmCOSSBT2PZeIljIRGNwlekHBKb71TGuFP4uHr7qMtx/ kcCvvhrilk7jdaB3ZPJKYD50nXqxWrwmErUDMF8zcJQT21JNjSZ284/8IDLod/eiDDT/ PLubk0kjlO7zmM746E7Gy1wl6SA3XUcESYgXaKUofNUCOFJWY6yuxi9ybpDYusMh5bqR LDx2Eqhjh4VkTBO1W5xNK+bGxqhHtsApWhl0lGUtmCT0pMvOKE9TS2LnFPrwtSXqJPsm gT6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Yw6fD9J4ML7PJDF5kBvosPIyEo8IsJ1SsMGunTYr7bQ=; b=hK1cTYbZ05U4hGAC57UkhQbQgoiglPOS28IvA3YobNIrofC75pLzbBUgfDJsa2HVDY 2ANoRzzhC5yHkOOOM1kYWQ/4pG2Y8rPfi5lEzBweYhNMCbj5PXkADbNk8nl27RT7TjTD 3nAdzD4I86uMhzCOYwSWcJ1WMVPQNSOy1JHZ9TtfOM/MxudfxjufsLPN7Foi5MyY+L3d 55LnYE2Ua+1d7pDo2F942T/gDl3kCxttqsR6hZhil32EqRqAeW/i8cJD1QUF2iBeZn8w CvQc4LHARJGNVM0TLO99EtA5SNGLhNKoTj17+46m2cXgV5j74ibw6Rv32Cfx2hFpuCWr lTqg== X-Gm-Message-State: AOAM531111v7v2gq9YjBpog8t+T94h8bNHhayWPITJSb5BG4r4Mq5nSY QTOwAGxYU0lhKHH9w7F8uZdrpIOOP2ERyYr+mNW1kqJ8 X-Google-Smtp-Source: ABdhPJzW0PfYpNwbwlTLddURP1Vgx/tTmU0zf+RFe7G68syst/VNOkHIQAPLxrJnoUKEb0n+ssf45IH28dbVoJemNEM= X-Received: by 2002:a17:90a:ae18:: with SMTP id t24mr73141pjq.92.1630691152348; Fri, 03 Sep 2021 10:45:52 -0700 (PDT) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 References: <2b59c3ae-8330-facd-def9-c0640c56cf3a@bruelltuete.com> In-Reply-To: <2b59c3ae-8330-facd-def9-c0640c56cf3a@bruelltuete.com> From: Ryan Stone Date: Fri, 3 Sep 2021 13:45:41 -0400 Message-ID: Subject: Re: String functions considered unsafe in kernel To: jo@bruelltuete.com Cc: FreeBSD Hackers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4H1QFN2jThz3vFb X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N It's straight-up a bug to do *anything* directly on a user-provided string. You must use copyinstr to copy it into a kernel buffer first, which guarantees null termination. In legacy cases where a user provided buffer could be legitimately not null-terminated, such as in a struct sockaddr_un, developers must take care to null-terminate the string themselves after copyin.