Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1642950pxb; Mon, 22 Feb 2021 07:19:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyU3/+NjYXvBpk1SmC/Jgwwq3yKFAVfkuLETVowDyPHOqj6vLyBqyJQJ9PyUU+KaY0qDcLy X-Received: by 2002:a05:6402:519:: with SMTP id m25mr21526446edv.289.1614007181877; Mon, 22 Feb 2021 07:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614007181; cv=none; d=google.com; s=arc-20160816; b=AmiOG8zSdPTeWFrf3T8B9wM1IP9z0RmAMdyR1oCg1yiO2pwDEhG0+xMDOJdyych5Oa E8XwJn8WobTAN0+UuBvqihdv6ApCrTjD9qocP+g+h79yvz3K/OnMCEjVhHwQzrFI6Hdz WQSpuwdn/S43PR/U1BU0C5JmT62RTguznQ3yIGY95fmFugRrYTYp20b8x2MG5QNds97m VOtHTJEXxcNREE279oi7mUGw3wP70wZPPP8SYspLOhJxy9rcxlNjXKp2J3I9LSgoxydQ Pm4rWdxPjI1tu2V6ejhBZ9XKm/joXQiTTwS5Y9vw2JtY+LU3EZhf/UHSBOopSq+4M1Zz ToBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DkOt0yrBVyRKH79yBKw6bfM0jQaRrACpcMjpjEsTbCk=; b=LplQOj9GUk8KLLySPACOXTpllLjv7ukXbAZiicZewue5aRCZ/hAzF8jtdLvBfFmMU4 kzaUXQLclxZWbS99nqWzGRD5pk0/uEkK2d23xlJBmauzm2cnd7fOtMAoX3U+yZU3Y83x VnVz0JNNRNIWAUtkLTQOKC5abuM8eIGl230KSM/mbiyUamyN1PLgeheXJcTA4EDNT698 sBJgOC1riwPvapehWUoy6v8u6rDpAhsPIGJuFNb+kkbqXGgSyFG7EBGUD35NIEFVK2Og iKnhwGmPz3LMuTT8lR40oQ4BKVm7ATRxCM/0p+t0Tg1xIMjazi2Yxi4KKLrQYgXBhZCR ROYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XovTNWHw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r15si11740409ejj.134.2021.02.22.07.19.18; Mon, 22 Feb 2021 07:19:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XovTNWHw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231599AbhBVPSs (ORCPT + 99 others); Mon, 22 Feb 2021 10:18:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231255AbhBVPOJ (ORCPT ); Mon, 22 Feb 2021 10:14:09 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6AC3C061356 for ; Mon, 22 Feb 2021 07:12:54 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id r3so7812386wro.9 for ; Mon, 22 Feb 2021 07:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DkOt0yrBVyRKH79yBKw6bfM0jQaRrACpcMjpjEsTbCk=; b=XovTNWHwTCos9xzXipmutbAdCB13MpWujMUaUW7i4hXpx6rYXFXRPIZ8/iNIwrIi2R IbP55z5TmCskc2vHnE7UiDvlds9Z4mcKkR0XlN2D3QfmOmA+nY0FgXuDfsvASdnr3ug3 czItvGV4svJ/yme+wrTkvACH9L18hK0r1/zHtY+6xV+8xbuoGUGOBpls8YgfkWLuxWBa 91YJKDhrgBm2P2OxXOxoUunNoOsDqTJcdQI2B7Chr/RrYqxeCm3jBUh0z5PE43xzj+Fs tWiylFYaUFkWZvLYXuEpybk/gQzm7sudrmZpNp3/2HLP7goAXFs5HwUHuZEsY0S7zSKy ZGXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DkOt0yrBVyRKH79yBKw6bfM0jQaRrACpcMjpjEsTbCk=; b=RmDMWEe7ztG6FV/PBG2vZQNoBLxEDiCvaBz0sUSbWEWqO3DoQlVvwYwJx5xvfcMB8U SbbdtIodC1diXGzV0GQp9WwmeJqH8JBqcnNZRZ7wVuLps9MFoFAmPG4/lp6kjvLt2gLU v/hneWbcdj7NPFL0TAy5eaf3TB29qSUwqq2n2MTbLdrh8uorH5/7qKXtBlA3wSyjSPzH jvhqfY9sad9VniF+V867OOsIOI9IKQxDWlrxySlN4iDA2EkrQQz/SHoLb/j9RLGxRIQL Qu20yZrihEdGj7cZGGyVsr1Eqsw44RKUigaFv+os+4DtacXo1AOqTEfaI8Fj+JBKeDll 29Bw== X-Gm-Message-State: AOAM530TygQz6Qkc3w+BcT0BkPjxOPRkfkgBSvAnqimqk3gjSWZhWKiq xaZBrj9v6jIn2h1jf+lqOxF8u5JdLtvYS1u8v4s= X-Received: by 2002:a5d:524b:: with SMTP id k11mr1010025wrc.122.1614006773420; Mon, 22 Feb 2021 07:12:53 -0800 (PST) Received: from debby (176-141-241-253.abo.bbox.fr. [176.141.241.253]) by smtp.gmail.com with ESMTPSA id y5sm12788081wrh.38.2021.02.22.07.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 07:12:52 -0800 (PST) From: Romain Perier To: Kees Cook , kernel-hardening@lists.openwall.com, Geert Uytterhoeven Cc: Romain Perier , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/20] m68k/atari: Manual replacement of the deprecated strlcpy() with return values Date: Mon, 22 Feb 2021 16:12:20 +0100 Message-Id: <20210222151231.22572-10-romain.perier@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210222151231.22572-1-romain.perier@gmail.com> References: <20210222151231.22572-1-romain.perier@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The strlcpy() reads the entire source buffer first, it is dangerous if the source buffer lenght is unbounded or possibility non NULL-terminated. It can lead to linear read overflows, crashes, etc... As recommended in the deprecated interfaces [1], it should be replaced by strscpy. This commit replaces all calls to strlcpy that handle the return values by the corresponding strscpy calls with new handling of the return values (as it is quite different between the two functions). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy Signed-off-by: Romain Perier --- arch/m68k/emu/natfeat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/m68k/emu/natfeat.c b/arch/m68k/emu/natfeat.c index 71b78ecee75c..fbb3454d3c6a 100644 --- a/arch/m68k/emu/natfeat.c +++ b/arch/m68k/emu/natfeat.c @@ -41,10 +41,10 @@ long nf_get_id(const char *feature_name) { /* feature_name may be in vmalloc()ed memory, so make a copy */ char name_copy[32]; - size_t n; + ssize_t n; - n = strlcpy(name_copy, feature_name, sizeof(name_copy)); - if (n >= sizeof(name_copy)) + n = strscpy(name_copy, feature_name, sizeof(name_copy)); + if (n == -E2BIG) return 0; return nf_get_id_phys(virt_to_phys(name_copy));