Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752974AbcLFUWN (ORCPT ); Tue, 6 Dec 2016 15:22:13 -0500 Received: from mail-wj0-f195.google.com ([209.85.210.195]:36028 "EHLO mail-wj0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751139AbcLFUWK (ORCPT ); Tue, 6 Dec 2016 15:22:10 -0500 From: Alex Yashchenko To: dhowells@redhat.com Cc: keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, Alex Yashchenko Subject: [PATCH] sign-file: Fix inplace signing when src and dst names are both specified Date: Tue, 6 Dec 2016 23:20:08 +0300 Message-Id: <1481055608-8101-1-git-send-email-alexhoppus111@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1119 Lines: 39 When src and dst both are specified and they point to the same file the sign-file utility will write only signature to the dst file and the module (.ko file) body will not be written. That happens because we open the same file with "rb" and "wb" flags, from fopen man: w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. ... bm = BIO_new_file(module_name, "rb"); ... bd = BIO_new_file(dest_name, "wb"); ... while ((n = BIO_read(bm, buf, sizeof(buf))), n > 0) { ERR(BIO_write(bd, buf, n) < 0, "%s", dest_name); } ... Signed-off-by: Alex Yashchenko --- scripts/sign-file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sign-file.c b/scripts/sign-file.c index 53af6dc..0672c0d 100755 --- a/scripts/sign-file.c +++ b/scripts/sign-file.c @@ -267,7 +267,7 @@ int main(int argc, char **argv) } x509_name = argv[2]; module_name = argv[3]; - if (argc == 5) { + if (argc == 5 && strcmp(argv[3], argv[4])) { dest_name = argv[4]; replace_orig = false; } else { -- 1.9.1