Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7928301imu; Thu, 15 Nov 2018 03:57:10 -0800 (PST) X-Google-Smtp-Source: AJdET5eeZJwP/H53sUI2VCLd0LSVJsAovYt4SworZlc0dlQGceQgUJaGJZVIXBdMgnleBxyoZjyF X-Received: by 2002:a17:902:bd4a:: with SMTP id b10mr6012137plx.232.1542283030247; Thu, 15 Nov 2018 03:57:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542283030; cv=none; d=google.com; s=arc-20160816; b=NP8c/y4VXysMyg9QrcvN82KVcDoKKIngkgfnk0KxQhZhE4a2yXQnJ0NLu/ykj7TDJ0 ec89r7I6RUNziIijOi+mIfbHi4SCtDn6oE4kLHvNcbOelgSu52ZxhMXApJU+xwE3ORaG w1TfSDzqbNODT5ZROcjWzhoa5JNjADlHe40NOQT+dqOv8hyyIaeI/mxGO9SYzEq5uiUY JmjACSaJ9XAeQza6vOLITpaAtC9EzmI2ut2N7pN8XbEgtOIsqZyCU9hrtpHl/G05wrU2 zHI9jczdoqKjxk0L0zPMmuswOP4F7nJAGQqL1mrvBvQtXMnMFvaeTGClgGot4u4KmboK fgkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=G8Y5W7rc30RQqIF5Pik9YN0alb5dkx5ewzntHywNtZw=; b=BOkcs5ytQWA+UnFe0y7I73ZPWtXHTEcCT50e6lNpfWB7uhSr3HSna4MSnf0BqZE+pi KTJdX85utgUYdvGiwoGs8Ocd7JjJcTe3IBJlKvAxedCN6NptFB6QDZYsiiZxftcx4UAs 2gw/Fvg057GBwDHXieG9WarHG8saj1666+8b7VBwhK0Vm13+gdS7ITYEe4oiNW0tZa9D at2a47MDTRJPfjRElh2mYGcI6XByB1Gxec5U683CcCY5O65kYaNCZjhsFNVnioypDFB7 kXRYAhWzSnDZAKOdBJ0YTn8O7o8JxxbTbxsXoNxp5hQRJlXdh6EC+vG1MhO3BBQR6pt3 7JyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gRcYi+IN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id v9si19563149pgt.464.2018.11.15.03.56.55; Thu, 15 Nov 2018 03:57:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gRcYi+IN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2387687AbeKOWD2 (ORCPT + 99 others); Thu, 15 Nov 2018 17:03:28 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:39581 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728859AbeKOWD2 (ORCPT ); Thu, 15 Nov 2018 17:03:28 -0500 Received: by mail-it1-f194.google.com with SMTP id m15so28820920itl.4; Thu, 15 Nov 2018 03:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=G8Y5W7rc30RQqIF5Pik9YN0alb5dkx5ewzntHywNtZw=; b=gRcYi+INg2y+WboP7xR74ve4nXnLsk0/pjfsJH2e10fu0K2bnKWHkyY15VSeNjMQXS hTu2Ze5qyCycLYOH2gEzZu9uX20xqdsPOPh3+wSKBh4k8bK1HUmSBmxaDAoSlzqErdGW ImY1SoelcKQl3oUe+JJ8ZeaopsG204jMecVCmY9Eo6dEvvy6ojSncU3qFUFjfGOQfCP1 b6xsRgZtWV9bf6MQsc+AvGKoWKu55ofj7KpuLRnrdWDjqex5cZacPI5A0TTSgTeivHR8 FMioyxuiAd58gAoVPe6GQabADgqOFB1oyBkPkA7CyPTwrwG525DlizW3aaeWEeYw+iwt qkOw== 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=G8Y5W7rc30RQqIF5Pik9YN0alb5dkx5ewzntHywNtZw=; b=BGJHrd2O4N0UnBd+utM1yHWy5VuOJsjxWJrEle1oT/5X7NTNuuNfeYmRI+UEOmst4H LvgJLKWx7x7mkV1Xkx1UDqK7CvqEBj/Pc3OVDMvL2a7j+94L20GIP6ELKU775TA5Dna5 ap8WSJBhPGRGW9upecLB8Nq21ZnMVjaUYPp/ZVe6Gq9bMUMhSsnZUM/5rTTfWv+XDara vYcChAT+O74/WJAVncboP2LcTyf/QzqLQV8OaBySkyG+6S1xoNS/EKgmG+WbF2sbX5Cj pNQcxpmHa72bGJQmco2TY1r4QDJsreLhLCZET0SU6IpwT1pA660P7w1VNj3W87hEFPD+ 5/wg== X-Gm-Message-State: AGRZ1gK4haX665cxnG33GRZwtyf1IuG6Ps/PxG1+3bmZepvc35ngItsc zda+BGkHnaT0ZCuoB8zwlVa/XClwr+abuuexw0s= X-Received: by 2002:a02:ba01:: with SMTP id z1mr5494861jan.100.1542282955397; Thu, 15 Nov 2018 03:55:55 -0800 (PST) MIME-Version: 1.0 References: <20181114131642.21425-1-dh.herrmann@gmail.com> In-Reply-To: From: David Herrmann Date: Thu, 15 Nov 2018 12:55:44 +0100 Message-ID: Subject: Re: [PATCH] Revert "HID: uhid: use strlcpy() instead of strncpy()" To: Kees Cook Cc: labbott@redhat.com, "open list:HID CORE LAYER" , linux-kernel , Jiri Kosina , Benjamin Tissoires , xiongfeng.wang@linaro.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi On Thu, Nov 15, 2018 at 12:09 AM Kees Cook wrote: > On Wed, Nov 14, 2018 at 9:40 AM, Laura Abbott wrote: [...] > > Can we switch to strscpy instead? This will quiet gcc and avoid the > > issues with strlcpy. > > Yes please: it looks like these strings are expected to be NUL > terminated, so strscpy() without the "- 1" and min() logic would be > the correct solution here. "the correct solution"? To my knowledge the original code was correct as well. Am I missing something? > If @hid is already zero, then this would > just be: > > strscpy(hid->name, ev->u.create2.name, sizeof(hid->name)); > strscpy(hid->phys, ev->u.create2.phys, sizeof(hid->phys)); > strscpy(hid->uniq, ev->u.create2.uniq, sizeof(hid->uniq)); > > If they are NOT NUL terminated, then keep using strncpy() but mark the > fields in the struct with the __nonstring attribute. They are supposed to be NUL terminated, but for compatibility reasons we allow them to be not. So I don't think your proposal is safe. Thanks David