`cupsdWritePrintcap`: `printer-info` written to printcap unescaped (control characters not neutralized)

オープン
#1,832 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c
領域
security

調査の方向性

Start in cupsdWritePrintcap() in scheduler/printers.c, where p->info is written raw in the BSD branch (around lines 3187 and 3195) and the Solaris branch (around lines 3291-3297). The validator behaviour is in ippValidateAttribute in cups/ipp.c. Build the reproduction program from the issue to confirm a raw LF is accepted for printer-info. Done means a printer-info containing a newline no longer produces a second printcap entry on either branch. Choosing between the three suggested fixes needs maintainer agreement first.

索引モデルが issue の本文から書いたものです。

説明

Summary

cupsdWritePrintcap() (scheduler/printers.c) writes p->info directly into the printcap
file without escaping control characters. Because printer-info is an IPP text-typed value,
ippValidateAttribute accepts a raw \n/\r/\t in it, so a printer-info containing a
newline passes validation and reaches the printcap writer unchanged. One embedded newline ends
the current printcap line and starts a second, fully attacker-shaped entry.

This is a hardening gap analogous to cupsFilePutConf() (cups/file.c:1334), which already
escapes #, \, \n, \r when writing the same Info value to printers.conf. The printcap
writer has no equivalent neutralization.

Root cause

1. The text validator exempts newlines. cups/ipp.c, ippValidateAttribute, text branch:

else if (_cups_iscntrl(*ptr) && *ptr != '\n' && *ptr != '\r' && *ptr != '\t')
{
    /* reject */
}

\n/\r/\t are explicitly allowed for IPP_TAG_TEXT. The name branch rejects all control
characters, which is why the earlier printer-name fix did not cover printer-info (it goes
through the text branch).

2. Both printcap writers emit p->info raw. scheduler/printers.c, cupsdWritePrintcap.
BSD branch (line 3195; the default-printer line at 3187 has the same shape):

cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info, ServerName, p->name);

Solaris branch (lines 3291-3297) writes description=%s from the same p->info, where a newline
ends the description= field and whatever follows becomes a new entry:

cupsFilePrintf(fp, "%s:\\\n\t:bsdaddr=%s,%s:\\\n\t:description=%s:\n",
               p->name, ServerName, p->name, p->info ? p->info : "");

Fixing only the BSD line leaves the Solaris path open.

Reproduction (validator differential)

val.c — shows a raw LF accepted in printer-info (text) and rejected in printer-name (name):

#include "cups/ipp.h"
#include "cups/cups.h"
#include <stdio.h>
#include <string.h>
int main(void){
  struct { const char *tag; const char *name; const char *val; } cases[] = {
    {"TEXT","printer-info","Office\nFAKE|spoof:rm=host:rp=q:"},
    {"NAME","printer-name","q\nFAKE"},
    {"TEXT","printer-info","Clean Office Printer"},
  };
  for (int i=0;i<3;i++){
    ipp_t *r = ippNew();
    ipp_tag_t vt = strcmp(cases[i].tag,"NAME")==0 ? IPP_TAG_NAME : IPP_TAG_TEXT;
    ippAddString(r, IPP_TAG_PRINTER, vt, cases[i].name, NULL, cases[i].val);
    int ok = ippValidateAttributes(r);
    printf("%-5s %-16s raw-LF=%d -> %s\n", cases[i].tag, cases[i].name,
           strchr(cases[i].val,'\n')?1:0, ok?"ACCEPTED":"rejected");
    ippDelete(r);
  }
  return 0;
}

Output (built against the tree with clang -I. -Icups -D_CUPS_SOURCE):

TEXT  printer-info      raw-LF=1 -> ACCEPTED
NAME  printer-name      raw-LF=1 -> rejected
TEXT  printer-info      raw-LF=0 -> ACCEPTED

With printer-info = "Office Printer\nINJECTED|desc:rm=host:rp=q:" stored on a queue, a printcap
rewrite produces two lines where only one was intended — the second is attacker-shaped:

EvilQueue|Office Printer
INJECTED|desc:rm=host:rp=q::rm=<server>:rp=EvilQueue:

printer-info reaches p->info unchanged via create_local_printer (scheduler/ipp.c:5985) and
add_printer (CUPS-Add-Modify-Printer), both of which mark the printcap dirty.

Suggested fix

Any one of these closes it; the first is the most contained:

  1. Escape control characters in both printcap writers in cupsdWritePrintcap (BSD
    printers.c:3187/3195, Solaris 3291-3297), the same way cupsFilePutConf does for
    printers.conf.
  2. Strip \n/\r from printer-info (and printer-location) when it is stored.
  3. Have the text validator reject control characters for values that end up in line-oriented
    files.
主要言語
C
スター
1.8k
フォーク
367
平均マージ
1日 16時間
マージ済み PR(30日)
7

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OpenPrinting/cups のほかの issue

OpenPrinting/cups の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。